http://blog.paciellogroup.com/2012/05/html5-accessibility-chops-hidden-and-aria-hidden/
hidden
The HTML5 hidden
attribute provides a semantic indicator:
All HTML elements may have the
hidden
content attribute set. Thehidden
attribute is a boolean attribute. When specified on an element, it indicates that the element is not yet, or is no longer, relevant. User agents should not render elements that have thehidden
attribute specified.
<p hidden>This content is hidden.</p>
HTML5 hidden effects:
hidden
attribute)display:none
applied by browser.Indicates that the element and all of its descendants are not visible orperceivable to any user as implemented by the author.
<p aria-hidden="true">This content is hidden.</p>
<p aria-hidden="false">This content is not hidden.</p>
aria-hidden
effects:
aria-hidden
attribute)aria-hidden
content in the accessibility tree focusable content is included in tab order and is navigable and operable for AT users (as well as other users).invisible
. If IA2 is supported aria-hidden=true
is passed as an object attribute. If UIA is supported aria-hidden=true
is passed as an ARIA property.aria-hidden=false
is not mapped in any browser that supports aria-hidden, thus its use has no meaning or in other words has the same meaning as its absence.As mentioned, the standard method to hide content from all users in browsers that support CSS is and has been to use CSS display:none
.
<p style="display:none">This content is hidden.</p>
display:none
effects:invisible
. If UIA is supported OffScreen=true
.If you want to hide content from all users, use the HTML5 hidden
attribute (along with CSSdisplay:none
for browsers that do not yet support hidden) There is no need to use aria-hidden.
.hidden {display:none}
<p hidden class="hidden">this content is hidden from all users</p>
Use an off screen technique to remove content from visible display, but still available to screen reader users:
.offscreen
{position:absolute;
left:-10000px;
top:auto;
width:1px;
height:1px;
overflow:hidden;}
<div
class="offscreen"
>This text is hidden.</div>
Modified example code from: WebAIM – CSS in Action: Invisible Content Just for Screen Reader Users
Hiding interactive (focusable) content from visible display using the off screen technique means it is not visible, but still in the tab order and causes issues for keyboard only users. Focusable content should only be hidden from visible display if the focusable element becomes visible when it recieves focus:
a.offscreen
{position:absolute;
left:-10000px;
top:auto;
width:1px;
height:1px;
overflow:hidden;}
a.offscreen:focus
{position:relative;
left:0px;
width:auto;
height:auto;
overflow:auto;
}
<a class="offscreen" href="test.html">this link is offscreen unless it has focus</a>
Notes by Ted Drake, on use of the off screen technique described:
Using negative position can create long scroll bars when localizing a site for a rtl language. Also, it uses CSS properties that are commonly used and easy to accidentally over-ride.
The Yahoo Accessibility Lab recommends using clip for content that should be hidden from the visual user, yet available to screen reader users. Thierry Koblentz has a great article on this technique, as well as the underlying philosophy behind using the correct CSS techniques for hiding content. Clip your hidden content for better accessibility
Support for aria-hidden
, HTML5 hidden
and the off screen technique was tested using JAWS, Window Eyes and NVDA (Windows), ChromeVox (Chrome OS), VoiceOver (iOS and Mac OSX) and Orca (Linux) with supporting browsers for each OS.
hidden
(+ CSS display:none
) worked in all screen reader/browser combinations tested.aria-hidden=true
worked in some screen reader/browser combinations tested.aria-hidden=false
had no effect in any of the screen reader/browser combinations tested. In other words if content is hidden from all users using HTML5hidden
or display:none
applying aria-hidden=false
to the content does not make it visible to screen reader users.