311

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.

AndrewMk
  • 623
  • 2
  • 6
  • 16
Daniel Kobe
  • 9,376
  • 15
  • 62
  • 109

3 Answers3

423

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.

Michael Mainer
  • 3,387
  • 1
  • 13
  • 32
Leo Farmer
  • 7,730
  • 5
  • 31
  • 47
  • 4
    So if you just use hidden attribute, screen reader will still read? – Daniel Kobe Jun 29 '15 at 03:33
  • 48
    Correct. `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. – Andrei Bârsan Jun 29 '15 at 03:47
  • `aria-hidden` Indicates that the element and all of its descendants are not visible or perceivable to any user or the reader – Swatantra Kumar Jul 22 '16 at 09:44
  • 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. – eenblam Jul 25 '16 at 19:23
  • 9
    Your answer about `aria-hidden` is correct; however, you said nothing about `hidden` to differentiate it from `aria-hidden`. This is unfortunately the best answer. Please be more thorough on your answers. – Pegues Jan 17 '17 at 17:46
  • 2
    your answer explains the *effects* of the attributes, but not their *meaning*. you mention nothing about the accessibility tree or the temporal relevance of an element. read the specs for more info. [[HTML 5.2](https://www.w3.org/TR/html52/editing.html#the-hidden-attribute), [ARIA 1.1](https://www.w3.org/TR/wai-aria-1.1/#aria-hidden)] – chharvey Apr 12 '18 at 22:38
  • 1
    Point to remember is if its applied on parent , all child elements gets hidden – ShankPossible Jan 13 '20 at 08:50
  • Thank you for this. Google linked me to wrong information (https://web.dev/learn/forms/security-privacy/). On this page, they are promoting the use of `aria-hidden="true"` and `hidden` on the input tag. This combination is not valid according to W3C, so I'm glad to learn that I don't need the aria-hidden attribute. – chillywilly Jul 20 '22 at 21:52
50

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

Yangshun Tay
  • 49,270
  • 33
  • 114
  • 141
UnknownOctopus
  • 2,057
  • 1
  • 15
  • 26
  • 27
    This 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. – Andrei Bârsan Jun 29 '15 at 03:45
  • `aria-hidden` is used to hide the element from people using your website with accessibility tools. – Luke Brown Jun 29 '16 at 15:02
22

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

chharvey
  • 8,580
  • 9
  • 56
  • 95
  • 1
    This 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. https://developer.paciellogroup.com/blog/2012/05/html5-accessibility-chops-hidden-and-aria-hidden/ – RobW May 09 '18 at 15:59