I have been seeing the aria attribute all over while working with Angular Material. Can someone explain to me, what the aria prefix means? but most importantly what I'm trying to understand is the difference between aria-hidden
and hidden
attribute.
-
1I found some clarification here: paciellogroup.com/blog/2012/05/…– Honinbo ShusakuJun 29, 2015 at 2:49
-
Hidden removes from DOM tree, aria-hidden removes from accessibility tree– A McGuinnessApr 2, 2021 at 21:26
3 Answers
ARIA (Accessible Rich Internet Applications) defines a way to make Web content and Web applications more accessible to people with disabilities.
The hidden
attribute is new in HTML5 and tells browsers not to display the element. The aria-hidden
property tells screen-readers if they should ignore the element. Have a look at the w3 docs for more details:
https://www.w3.org/WAI/PF/aria/states_and_properties#aria-hidden
Using these standards can make it easier for disabled people to use the web.
-
4So if you just use hidden attribute, screen reader will still read? Jun 29, 2015 at 3:33
-
48Correct.
hidden
means hidden to everyone.aria-hidden
means hidden to screen readers and similar tools. This is useful for components which are used purely for formatting and contain no real content, for instance. Jun 29, 2015 at 3:47 -
29@AndreiBârsan @DanielKobe I think Andrei meant "Incorrect." (The rest of his comment is factual.)
hidden
should prevent the screen reader from accessing the tag's contents.– eenblamJul 25, 2016 at 19:23 -
9Your answer about
aria-hidden
is correct; however, you said nothing abouthidden
to differentiate it fromaria-hidden
. This is unfortunately the best answer. Please be more thorough on your answers.– PeguesJan 17, 2017 at 17:46 -
2
A hidden attribute is a boolean attribute (True/False). When this attribute is used on an element, it removes all relevance to that element. When a user views the html page, elements with the hidden attribute should not be visible.
Example:
<p hidden>You can't see this</p>
Aria-hidden attributes indicate that the element and ALL of its descendants are still visible in the browser, but will be invisible to accessibility tools, such as screen readers.
Example:
<p aria-hidden="true">You can't see this</p>
Take a look at this. It should answer all your questions.
Note: ARIA stands for Accessible Rich Internet Applications
Sources: Paciello Group
-
27This is not entirely correct (even the official documentation is a bit hazy here). An element with
aria-hidden="true"
is still visible in the browser, but will be invisible to accessibility tools, such as screen readers. Jun 29, 2015 at 3:45 -
aria-hidden
is used to hide the element from people using your website with accessibility tools. Jun 29, 2016 at 15:02
Semantic Difference
According to HTML 5.2:
When specified on an element, [the
hidden
attribute] indicates that the element is not yet, or is no longer, directly relevant to the page’s current state, or that it is being used to declare content to be reused by other parts of the page as opposed to being directly accessed by the user.
Examples include a tab list where some panels are not exposed, or a log-in screen that goes away after a user logs in. I like to call these things “temporally relevant” i.e. they are relevant based on timing.
On the other hand, ARIA 1.1 says:
[The
aria-hidden
state] indicates whether an element is exposed to the accessibility API.
In other words, elements with aria-hidden="true"
are removed from the accessibility tree, which most assistive technology honors, and elements with aria-hidden="false"
will definitely be exposed to the tree. Elements without the aria-hidden
attribute are in the "undefined (default)" state, which means user agents should expose it to the tree based on its rendering. E.g. a user agent may decide to remove it if its text color matches its background color.
Now let’s compare semantics. It’s appropriate to use hidden
, but not aria-hidden
, for an element that is not yet “temporally relevant”, but that might become relevant in the future (in which case you would use dynamic scripts to remove the hidden
attribute). Conversely, it’s appropriate to use aria-hidden
, but not hidden
, on an element that is always relevant, but with which you don’t want to clutter the accessibility API; such elements might include “visual flair”, like icons and/or imagery that are not essential for the user to consume.
Effective Difference
The semantics have predictable effects in browsers/user agents. The reason I make a distinction is that user agent behavior is recommended, but not required by the specifications.
The hidden
attribute should hide an element from all presentations, including printers and screen readers (assuming these devices honor the HTML specs). If you want to remove an element from the accessibility tree as well as visual media, hidden
would do the trick. However, do not use hidden
just because you want this effect. Ask yourself if hidden
is semantically correct first (see above). If hidden
is not semantically correct, but you still want to visually hide the element, you can use other techniques such as CSS.
Elements with aria-hidden="true"
are not exposed to the accessibility tree, so for example, screen readers won’t announce them. This technique should be used carefully, as it will provide different experiences to different users: accessible user agents won’t announce/render them, but they are still rendered on visual agents. This can be a good thing when done correctly, but it has the potential to be abused.
Syntactic Difference
Lastly, there is a difference in syntax between the two attributes.
hidden
is a boolean attribute, meaning if the attribute is present it is true—regardless of whatever value it might have—and if the attribute is absent it is false. For the true case, the best practice is to either use no value at all (<div hidden>...</div>
), or the empty string value (<div hidden="">...</div>
). I would not recommend hidden="true"
because someone reading/updating your code might infer that hidden="false"
would have the opposite effect, which is simply incorrect.
aria-hidden
, by contrast, is an enumerated attribute, allowing one of a finite list of values. If the aria-hidden
attribute is present, its value must be either "true"
or "false"
. If you want the "undefined (default)" state, remove the attribute altogether.
Further reading: https://github.com/chharvey/chharvey.github.io/wiki/Hidden-Content
-
1This post from Paciello Group, 2012 says: "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." Not sure if that's still the case, but adding as a caution. I'd love to describe my a11y view states separately from my CSS, but not sure it's possible with aria-hidden. developer.paciellogroup.com/blog/2012/05/…– RobWMay 9, 2018 at 15:59