Let's discuss the aria-live
attribute.
The aria-live
attribute is used to define the live region behavior for screen readers. It informs assistive technologies that content within the specified region may change dynamically and should be announced to the user.
<div aria-live="polite">
The status will be announced dynamically here.
</div>
In this example, the content within the <div>
with aria-live="polite"
will be announced by screen readers when it changes. The "polite" value indicates that the update is not urgent and won't interrupt the screen reader's current activity.
-
"off"
: The default value. Indicates that the live region should not be automatically announced. -
"polite"
: Indicates that changes in the live region are not critical; they will be announced when the screen reader is idle. -
"assertive"
: Indicates that changes in the live region are important and should be announced immediately, possibly interrupting the screen reader.
-
Use
aria-live
on regions that are dynamically updated to ensure screen reader users are informed of changes. -
Choose the appropriate value ("off," "polite," or "assertive") based on the urgency of the content changes.
-
Avoid placing
aria-live
on large or frequently changing sections, as it may lead to too much information being announced.
Consider a chat application where new messages dynamically appear. You might use aria-live
to ensure that screen reader users are informed of incoming messages:
<div aria-live="polite" class="chat-messages">
<!-- New chat messages dynamically added here -->
</div>
This ensures that screen reader users are notified of new messages as they arrive without interrupting their current interaction.