role="alert"
will announce a message assertively. Some screen readers will even announce the message as an "alert".
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.
Turn on your screen reader and press the submit button to hear the error message.