Visually hide an element with CSS

Categories


If you hide an element with display: none, it can also hide it from assistive technology, such as screen readers.

Using a visually hidden utility, you get the best of both worlds. A visually hidden element and assistive technology can still access it.

Code language
CSS
.visually-hidden {
  border: 0;
  clip: rect(0 0 0 0);
  height: auto;
  margin: 0;
  overflow: hidden;
  padding: 0;
  position: absolute;
  width: 1px;
  white-space: nowrap;
}

If you liked this post, you might like these ones, too

  1. Relative sizing with EM units

    Responsive units, like EM units, are super powerful and in this tutorial, you’ll learn how to use that power to give your front-ends resilience

    Continue
  2. Aligning description lists with CSS Grid

    🔥 A handy quick tip.

    Continue
  3. Create a semantic breakout button to make an entire element clickable

    Continue

Become a supporter by joining the Piccalilli Membership

For as little a $5 per month, you can get access to a private, friendly community, get a weekly newsletter and help to make as much content free as possible around here. If you join the $10 per month supporters club, you get access to premium tutorials and free access to mini courses!

Become a member

Sign up for updates

Stay up to date with updates from Piccalilli. You’ll get alerted as soon as any new content gets published. You’ll also get updates on upcoming courses and membership features! You can unsubscribe at any time, too.