How do I code a polite alert?

Question

What is the best way to code a polite alert?

Answer

A polite alert is a message which is presented by the screen reader after it has completed all queued announcements. Typically these should be used when you want to present a message to assistive technology without a user having to navigate to that message, but when the message is not important enough to warrant interrupting the screen reader's announcement of other content.

To create a polite alert, place an empty <div> on the web page and give that <div> an attribute of aria-live="polite". Then, when you wish to present the status message, inject the text into that <div>.

For a deeper dive into handling error alerts and other status messages, explore the "Forms: Labels, Cues, and Errors" course from Accessible Web Academy.

Free Tools to Continue Learning

Accessible Web Company Logo

Accessible Web RAMP

Monitor your website and manage your progress towards WCAG conformance.

Accessible Web Company Logo

Accessible Web Academy

Career specific courses to help power up your accessibility knowledge.