Accessible hidden content | The A11y Project

Great write up on the current best practices around hiding elements keeping all users in mind:

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

Or if you need to unhide when focused (better for keyboard users etc.):

.visually-hidden:not(:focus):not(:active) {
  /* ... */
}

Alternatively, need to hide an element from non-visual users (screen readers, smart speakers, reading mode), use aria-hidden: true and then if you also need to hide visually:

.my-component[aria-hidden="true"] {
  display: none;
}

Or use the HTML5 hidden attribute.

Explore Other Notes

Older

State of frontend 2020

Some interesting results from the latest Software House frontend survey. Surprised to see that over a third of respondents reckoned CSS-in-JS would be a "fad" and gone in three years; personally …

  • <!DOCTYPE html> <html> <head> <title></title> </head> <body> <p>Great write up on the current best practices around hiding elements keeping all users in …</p> </body> </html>
  • Murray Adcock.
Journal permalink