Skip to content

Linter Rule: Require href attribute on <a> tags ​

Rule: html-anchor-require-href

Description ​

Disallow the use of anchor tags without an href attribute in HTML templates. Use if you want to perform an action without having the user navigated to a new URL.

Rationale ​

Anchor tags without href are unfocusable if user is using keyboard navigation, or is unseen by screen readers.

Examples ​

✅ Good ​

erb
<a href="https://alink.com">I'm a real link</a>

🚫 Bad ​

erb
<a data-action="click->doSomething">I'm a fake link</a>
Add an `href` attribute to `<a>` to ensure it is focusable and accessible. (html-anchor-require-href)

References ​

Released under the MIT License.