Not everyone uses a mouse to explore a website. Good HTML must also make sense through a keyboard or screen reader.
What You Need to Know
Live regions let assistive technology announce small updates, such as Saved or Three results found. They work best for meaningful changes, not for every keystroke. Too many announcements can become distracting.
Try the Example
Take a look at the example. We’ll explain the important lines right below it.
<button id="save-button" type="button">Save draft</button>
<p id="save-status" role="status" aria-live="polite"></p>
<script>
const saveButton = document.querySelector("#save-button");
saveButton.addEventListener("click", () => {
document.querySelector("#save-status").textContent = "Draft saved";
});
</script>
Let’s Read the Code
- <button>: The button offers an action; its type or command determines what happens.
- <script>: Script contains JavaScript, data, or other browser-understood script formats depending on type.
- id: An id uniquely identifies an element on this page.
- type: Type changes what sort of control or resource the browser uses.
Read the named elements and attributes together. They explain how the browser connects this feature to the rest of the page.
What Happens in the Browser?
Try this with Tab and Shift+Tab. If you can, inspect the accessibility tree too; appearance alone does not tell the whole story.
What does assistive technology receive? The example includes aria-live. These relationships can explain names, states, or descriptions when used correctly. They do not automatically move focus, listen for clicks, or create keyboard handling.
Your Turn
Use Tab and Shift+Tab to visit the controls, then read their labels aloud. Is the purpose of each one clear?
Common Beginner Mistakes
- Judging the page only by how it looks, without checking its meaning and keyboard behavior.
- Check the same result using both the browser and a keyboard, not only by looking at the screen.
Key Takeaways
- Live regions let assistive technology announce small updates, such as Saved or Three results found.
- <button>: The button offers an action; its type or command determines what happens.
- Test the behavior you expect rather than trusting how the snippet looks in your editor.