role="alert" will announce a message assertively. Some screen readers will even announce the message as an "alert".

Usage

Since role="alert" may be announced as an "alert", it must only be used for notifications which require immediate attention. For example, an error message in a form field.

In order for role="alert" to work, it must be nested in the HTML. The error message must then be dynamically generated inside the element containing the attribute.

Example

Turn on your screen reader and press the submit button to hear the error message.