Eslint-plugin-jsx-a11y: anchor-is-valid - why <a href="#" /> is Invalid ?

Created on 14 Feb 2019  路  5Comments  路  Source: jsx-eslint/eslint-plugin-jsx-a11y

question with rules : anchor-is-valid

why <a href="#" /> is Invalid ?
it just make navigation . and i just use it to jump to the top of page. please teach me, thanks

question

Most helpful comment

You don鈥檛 need an element; all browsers send #top to the same place as #.

All 5 comments

You can use #top for that.

First, the href needs a specific target. AKA, which element with a blank ID are you targeting? Probably none, so place an element with, say, id="top" at the beginning of your page.

Second, anchor tags need contents, as described by the jsx-a11y/anchor-has-content linting rule

You don鈥檛 need an element; all browsers send #top to the same place as #.

Thanks @ljharb ! Good to know

To answer the original question; it's because # is almost exclusively abused to make a link that doesn't actually go anywhere, so they can add JS behavior. #top, at least, is explicit.

Was this page helpful?
0 / 5 - 0 ratings