Colmjude

Notes

A collection of TILs, snippets and thoughts
<< Back to notes

Hide element from users

Last updated 07 May 2020

Different ways to hide things from various user groups.

From all users, add CSS:

display:none
visibility:hidden // some screen readers ignore display: none

To hide visually but still be accessible by screenreaders

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

Hide from screenreaders, use aria-hidden attribute

aria-hidden="true"

E.g.

<span aria-hidden="true">Here be redundant or extraneous content</span>

Note that this has mixed browser and screen-reader support.

Further reading

Tags
html / accessibility / design / frontend