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.