DEV Community

Cover image for A11y tips: hide content from screen readers
Carlos Espada
Carlos Espada

Posted on

5 1

A11y tips: hide content from screen readers

If you want to hide content for screen readers but still be available to sighted or keyboard users, just use aria-hidden="true".

A classic example where it is useful is to hide icons that serve as visual support for a text:

<style>
  .icon-star: before {content: "★"; }
</style>

<span>
  <span class="icon-star" aria-hidden="true"></span>
  Favorite
</span>
Enter fullscreen mode Exit fullscreen mode

In this way the icon that we insert with CSS only appears for sighted users, while screen readers will announce only "Favorite", instead of "Black Star Favorite".

It is best to avoid using this ARIA attribute on focusable elements, as being able to receive focus but hiding from screen readers can cause confusion for their users. You could use a tabindex="- 1" to avoid focus but then it would be out of use for sighted keyboard users.

This and other tips on the use of aria-hidden="true" can be found in the already named article by Scott O'Hara, and on the use of icon fonts in the article by Zach Leathermann, from which the example is taken.

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more