Skip to content

Linter Rule: Focusable elements should not have aria-hidden="true"

Rule: html-no-aria-hidden-on-focusable

Description

Prevent using aria-hidden="true" on elements that can receive keyboard focus. When an element is focusable but hidden from screen readers, it creates a confusing experience where keyboard users can tab to "invisible" elements.

Rationale

Elements with aria-hidden="true" are completely hidden from assistive technologies, but they remain visible and interactive for mouse and keyboard users. If a focusable element is hidden from screen readers, keyboard-only users (especially those using screen readers) will encounter focused elements that provide no accessible information, creating a broken user experience.

Examples

✅ Good

erb
<button>Submit</button>
<a href="/link">Link</a>
<input type="text">
<textarea></textarea>

<div aria-hidden="true">Decorative content</div>
<span aria-hidden="true">🎉</span>

<button tabindex="-1" aria-hidden="true">Hidden button</button>

🚫 Bad

erb
<button aria-hidden="true">Submit</button>
Elements that are focusable should not have `aria-hidden="true"` because it will cause confusion for assistive technology users. (html-no-aria-hidden-on-focusable)
<a href="/link" aria-hidden="true">Link</a>
Elements that are focusable should not have `aria-hidden="true"` because it will cause confusion for assistive technology users. (html-no-aria-hidden-on-focusable)
<input type="text" aria-hidden="true">
Elements that are focusable should not have `aria-hidden="true"` because it will cause confusion for assistive technology users. (html-no-aria-hidden-on-focusable)
<textarea aria-hidden="true"></textarea>
Elements that are focusable should not have `aria-hidden="true"` because it will cause confusion for assistive technology users. (html-no-aria-hidden-on-focusable)
<select aria-hidden="true">
Elements that are focusable should not have `aria-hidden="true"` because it will cause confusion for assistive technology users. (html-no-aria-hidden-on-focusable)
<option>Option</option> </select> <div tabindex="0" aria-hidden="true">Focusable div</div>
Elements that are focusable should not have `aria-hidden="true"` because it will cause confusion for assistive technology users. (html-no-aria-hidden-on-focusable)
<a href="/link" aria-hidden="true">Hidden link</a>
Elements that are focusable should not have `aria-hidden="true"` because it will cause confusion for assistive technology users. (html-no-aria-hidden-on-focusable)

References

Released under the MIT License.