DEV Community

Carlos Viteri
Carlos Viteri

Posted on • Edited on • Originally published at c4rlosviteri.dev

3 1

Accessible components: Alerts

Alerts are a very common pattern to provide feedback messages for user actions such as error, warning or information. Do you know how to create a truly accessible alert? In this tutorial, we will learn how to create one.

There are two ways of creating WAI-ARIA compliant alerts. We will take a look at both.

The easiest and recommended one is to add an aria-role="alert". This role is used to communicate an important message to the user.

<div role="alert">
  <p>Alert example: Here should be the alert content</p>
</div>

On the other hand, we can create an alert by adding two aria attributes:

  • aria-live="assertive" whatever text change in the children nodes of this attribute will interrupt the current process in the assistive technologies to notify immediately this change to the user.
  • aria-atomic="true" this attribute tells the assistive technologies to read the entire content of the alert event if just a portion of it has changed.
<div aria-atomic="true" aria-live="assertive">
  <p>Alert example: Here should be the alert content</p>
</div>

Sometimes you will want the user to close the alert. To do it, you have to add a close labeled button by using an aria-label, only if the text inside the button is not descriptive enough.

<div role="alert">
  <button aria-label="Close alert">×</button>
  <p>Alert example: Here should be the alert content</p>
</div>

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay