Shouldn't the following be considered valid?
<a name="my-anchor">...</a>
It currently generates warnings:
The href attribute is required for an anchor to be keyboard accessible. Provide a valid, navigable address as the href value. If you cannot provide an href, but still need the element to resemble a link, use a button and change it with appropriate styles. Learn more: https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/anchor-is-valid.md jsx-a11y/anchor-is-valid
Why? Since html5 you wouldn't generally want an <a name> any more, you'd use an ID on the appropriate element.
Using the tag can be useful for decorating the anchors or exposing them through browser extensions (e.g. Display #Anchors).
Everything with an ID is an anchor in HTML5, so I think that extension probably just isn't really useful in the modern web. Can you elaborate on what you mean by "decorating"?
I just meant by styling. I've seen pages that use a faint dotted underline on anchors that are intended for external linking.
Anyway, you're probably right that I could just use id instead. Still, it doesn't seem like this rule should flag <a name> as invalid just because there are other ways to accomplish an anchor.
Perhaps not, but it鈥檚 not just that there鈥檚 other ways - <a name> is widely discouraged/deprecated in favor of using IDs.
I did some more research, and the HTML5 spec calls it "obsolete but conforming". That's not as strong as deprecated, but I suppose it's official enough that there's no point in changing the rule. Thanks for the quick response, @ljharb!
Most helpful comment
I did some more research, and the HTML5 spec calls it "obsolete but conforming". That's not as strong as deprecated, but I suppose it's official enough that there's no point in changing the rule. Thanks for the quick response, @ljharb!