Four axes for comparing hide-in-CSS techniques

Hiding content in CSS looks like a solved problem until you need the behavior to be predictable. The techniques developers reach for most often differ in layout, rendering and assistive-technology behavior, so the right choice depends on intent. To compare them, four questions are worth asking:

  • Accessibility: does a screen reader still announce the content?
  • Document flow: does the hidden element affect the layout?
  • Rendering: is the element's box model generated?
  • Event triggers: can the element receive clicks or focus?

One caution before the list: display: none is the most common way to hide content, but it also makes that content inaccessible to screen readers. That matters when the goal is only visual concealment.

Removing the element: display

With display: none the element stays in the DOM and remains visible in markup/inspection, but is never generated or rendered, and neither are any of its children. Click and hover listeners don't fire, and screen readers ignore the content. In a demo with three buttons and click handlers, only the two visible buttons render and register clicks.

This property alone changes whether image requests fire. An <img> tag set to display: none — inline or via selector — is still downloaded, while an image applied through the background property is not. The reason is that the parser hasn't applied CSS when it encounters the <img> tag. All current browsers behave this way; the exception is IE 11, which downloads in both cases.

MetricResult
Is the hidden content read by a screen reader?❌
Will the hidden element affect the document layout?❌
Will the hidden element’s box model be rendered?❌
Does the element detect clicks or focus?❌

Rendering without showing: visibility and opacity

visibility: hidden also visually hides the element, but it is generated and rendered — its box model exists and keeps occupying space. From there it matches display: none: screen readers don't see it and events don't register. The demo reuses the three-button example, swapping one property for the other.

MetricResult
Is the hidden content read by a screen reader?❌
Will the hidden element affect the document layout?✅
Will the hidden element’s box model be rendered?✅
Does the element detect clicks or focus?❌

opacity: 0 touches only the visual layer. The element is fully transparent yet behaves like any other element: screen readers can still read it and it can register clicks. Structurally it resembles visibility, with accessibility and event handling as the points of divergence.

MetricResult
Is the hidden content read by a screen reader?✅
Will the hidden element affect the document layout?✅
Will the hidden element’s box model be rendered?✅
Does the element detect clicks or focus?✅

Moving it off-screen: position

Absolute positioning takes an element out of document flow, so the page reserves no space for it; the element is positioned against its nearest positioned ancestor, or the document root if there is none. Offsetting it toward the top-left with values of -9999px pushes it where it can't be seen — the closest method so far to accessible hiding.

.hidden {
  position: absolute;
  top: -9999px;
  left: -9999px;
}
MetricEffect
Is the hidden content read by a screen reader?✅
Will the hidden element affect the document layout?❌
Will the hidden element’s box model be rendered?✅
Does the element detect clicks or focus?✅

Focusable content inside that element exposes the flaw: when it receives focus, the page scrolls to it and the viewport jumps.

The "visually hidden" class

A more robust accessible pattern combines absolute positioning, the clip property and hidden overflow. Scott O'Hara wrote it up in 2017, and each piece addresses a specific failure:

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

Take it out of flow. position: absolute removes the element without pushing it off-screen.

.visually-hidden {
  position: absolute;
}

Collapse it to a point. Zero width and height can be ignored by some screen readers, so use 1px. Content will overflow that space, so pair it with overflow: hidden.

.visually-hidden {
  height: 1px;
  overflow: hidden;
  position: absolute;
  width: 1px;
}

Clip the remaining square. The clipping property hides the one-pixel artifact without affecting screen readers. Note that clip was deprecated in favor of clip-path, but it is still required for older Internet Explorer support.

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

Fix smushed text. Off-screen accessible text can lose the white space between words, so "Welcome back home" is read as "Welcomebackhome." white-space: nowrap resolves it.

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

Restore focus visibility. Elements that support native focus and active states should display again when focused, while paragraphs and similar content stay hidden. The :not pseudo-selector handles the split.

.visually-hidden:not(:focus):not(:active) {
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  height: 1px;
  overflow: hidden;
  position: absolute;
  white-space: nowrap;
  width: 1px;
}
MetricResult
Is the hidden content read by a screen reader?✅
Will the hidden element affect the document layout?❌
Will the hidden element’s box model be rendered?❌
Does the element detect clicks or focus?✅

Other approaches worth knowing

text-indent can push text off-screen like the position method, but it doesn't work with RTL writing modes, making it less adaptable. transform can scale or move an element away; like opacity, it affects only the visual layer.

.hidden {
  text-indent: -9999em;
}
.hidden {
  transform: scale(0);
}

Choosing a method

Reaching for the visually hidden class gives visual concealment with accessibility intact, but that doesn't retire display: none — it remains the correct way to hide something completely, both visually and from assistive technology. For the inverse goal, hiding content from screen readers while keeping it visible, use the aria-hidden="true" attribute.

MetricDisplayVisibilityOpacityPositionAccessible Way
Is the hidden content read by a screen reader?❌❌✅✅✅
Will the hidden element affect the document layout?❌✅✅❌❌
Will the hidden element’s box model be rendered?❌✅✅✅❌
Does the element detect clicks or focus?❌❌✅✅✅