Hiding Content: hidden, inert and Visually Hidden

Intermediate · 12 min

Which ways of hiding content remove it from the screen, the accessibility tree and the tab order: hidden, inert, aria-hidden, opacity and visually-hidden text.

Before thisAccessible Names and Descriptions

Steve Griffith - Prof3ssorSt3v3 · 12 min

Hiding Content: hidden, inert and Visually Hidden

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by Steve Griffith - Prof3ssorSt3v3Report a problem with this video
Not started
Set this lesson's status

What you'll learn

  • Hiding has three separate effects: what is painted, what is in the accessibility tree, and what can take focus. Each technique changes a different combination.
  • `hidden`, `display: none`, `visibility: hidden` and `inert` removed content from the tree and the tab order in a test. `aria-hidden="true"` removed it from the tree only.
  • `opacity: 0` and a clipped one-pixel box stay in the tree. The second is the visually-hidden pattern for text only assistive technology should hear. The first is almost always a bug.
  • `inert` makes a subtree unfocusable, unclickable and invisible to assistive technology without hiding it. Use it for content that is visible but should not respond, such as the page behind a modal.
  • `hidden="until-found"` keeps content searchable: find-in-page or a URL fragment reveals it and fires `beforematch`.

Three questions about “hidden”

“Hide this” can mean three different things. Don’t paint it. Don’t announce it. Don’t let it take focus. The techniques overlap only partly, and picking the wrong one is how pages end up with invisible focus traps and double announcements.

I tested each in Chromium 159, reading the real accessibility tree through the DevTools protocol and pressing Tab through the page:

Technique Painted In the tree Tab can reach it
hidden attribute no no no
display: none no no no
visibility: hidden no no no
inert yes no no
aria-hidden="true" yes no yes
opacity: 0 no (transparent) yes yes
clipped 1px box no yes text only

The two traps

aria-hidden on something focusable. The tree says nothing is there, the keyboard says otherwise. In the test the button and link inside an aria-hidden container were reached by Tab. A sighted keyboard user would see focus land on them, a screen reader user would hear nothing, or worse, hear an unnamed control. ARIA rules forbid it for this reason.

opacity: 0 as “hidden”. The element is invisible but present: still announced, still focusable. It is fine as a fade-out end state combined with another technique, and a bug on its own.

Visually hidden: hide the pixels, keep the text

Sometimes you want the opposite: sighted users get an icon, screen readers get words. The pattern is a class that shrinks the box instead of removing it:

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}

A paragraph with that class stayed in the tree in the test. It is how an icon button gets its name (names lesson) and how a skip link is built. The accessible CSS lesson shows the same table from the CSS side.

inert

inert is the newest and most useful of these. It marks a subtree as non-interactive: it can’t be focused, clicked or selected, and assistive technology skips it, yet it still renders. In the test an inert button could not be clicked even with a forced click, was never reached by Tab, and neither it nor its text appeared in the tree. That is exactly what you want for the page behind a modal, an off-screen drawer, or a section that is visible but disabled while saving. inert is Baseline, available across the major browsers since April 2023 according to web-features. Modals made with dialog.showModal() apply this for you.

Only use it when the content is also visually obscured or clearly disabled, or sighted users will be confused why things don’t respond.

hidden=“until-found”

Plain hidden makes content unfindable, which is awkward for collapsed sections. hidden="until-found" keeps it findable. In the test the element reported content-visibility: hidden, and navigating to #ufp, an id inside it, removed the attribute and fired beforematch in all three engines I ran. The web-features data lists support as Chrome 102 and Firefox 148 with no Safari entry, so treat it as an enhancement, with a fallback for browsers that treat the value as plain hidden. The <details> element gets a similar reveal-on-find behaviour for free: a fragment link to text inside a closed details opened it in every engine I tested.

What the video covers

Steve Griffith’s “Enhanced UI control and Responsible Accessibility with the HTML INERT Property” (June 2024, about 12 minutes). The description says inert is now supported across browsers and can mark content users shouldn’t interact with, and links to his demo code and MDN. I could not read a transcript, so I do not describe the demo. It covers inert only; the table, aria-hidden, visually-hidden and until-found parts are my own tested prose.

Where this fits

This closes the tree-shaping part of the accessibility group, after names. Testing HTML accessibility comes next, and the dialog element uses inert behaviour.

Check yourself

  1. 01Why is `aria-hidden="true"` on a container with a button inside a bug?

    It removes the button from the accessibility tree but not from the tab order. In a test Tab still landed on the button, so a keyboard user focuses a control a screen reader cannot announce. Use `hidden`, or `inert` if the content must stay visible.

  2. 02You need a label that screen readers hear but sighted users do not see. What do you use?

    A visually-hidden class that clips the element to a one-pixel box. In a test this kind of paragraph stayed in the tree. `display: none` and `hidden` would remove it for everyone.

  3. 03What does `inert` do that `aria-hidden` does not?

    It blocks interaction as well. In a test an `inert` button could not be clicked or tabbed to, and both it and its text were absent from the tree. `aria-hidden` left the controls clickable and focusable.

  4. 04What is `hidden="until-found"` for?

    Collapsed content that find-in-page and `#fragment` links should still reach, like an accordion. When a match is found the browser removes the attribute and fires `beforematch`. In a test a fragment link did exactly that. Support is not universal, so check before relying on it.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark