An alert communicates an important change or problem. Text should tell the reader what happened and what to do next.
What You Need to Know
Role=alert may cause assertive announcements in assistive technology when inserted dynamically. Do not use it for every success message or static paragraph; use a calmer status when urgency is low.
The goal is not to collect as many tags as possible. Pick the element that best describes what the content really is.
Example: See It in Action
Take a look at this small piece of HTML. You can use it in a practice document and change the text to make it your own.
This is a short HTML fragment. To try it as a webpage, put it inside the body element of a complete HTML document.
<div role="alert">
<strong>Something went wrong.</strong>
<p>Please check your email address and try again.</p>
</div>
<p>Don't use an urgent alert role for every notice.</p>
Let’s Understand the Example
- Div groups content but has no special meaning of its own; prefer a meaningful element when one fits.
- Strong marks text as particularly important. It means more than simply making words bold.
- A p groups a paragraph of related text. Start another paragraph for a new thought.
- Role describes an accessibility role when native HTML semantics do not already provide it.
Look for the text “Something went wrong.” in the page. If the visible result surprises you, inspect the rendered elements to see what the browser actually built.
What Should You See?
The page should include “Something went wrong.”. If it looks different from what you expected, open developer tools and compare the source with the elements the browser created.
Try removing one piece of markup in a scratch copy, refresh the page, and compare the behavior. This is often the fastest way to understand what that piece contributes.
Try It Yourself
- Rewrite an urgent error so it includes a clear next step.
- Save your changes, open or refresh the page, and compare the result with the original example.
- Tell a friend what your change did. If you are not sure, undo it, refresh the page, and compare.
Common Beginner Mistakes
- Marking every decorative notice as role=alert and interrupting screen-reader users.
- Avoid picking tags just for their default bold, italic or spaced appearance. Use CSS for presentation.
Key Takeaways
- An alert communicates an important change or problem.
- Div groups content but has no special meaning of its own; prefer a meaningful element when one fits.
- Role=alert may cause assertive announcements in assistive technology when inserted dynamically. Do not use it for every success message or static paragraph; use a calmer status when urgency is low.