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
Tabindex changes whether and how an element participates in keyboard focus. Most links, buttons, and form controls work naturally without it. Avoid positive values that create a surprising focus order.
In this example: focus an error summary programmatically.
Try the Example
Take a look at the example. We’ll explain the important lines right below it.
<p>Press Tab to move through the controls below.</p>
<a href="/lessons">Browse lessons</a>
<button type="button">Start quiz</button>
<section id="message" tabindex="-1"><h2>Quiz result</h2></section>
Let’s Read the Code
- tabindex: Tabindex affects sequential keyboard focus; positive values are usually a poor choice.
- <button>: The button offers an action; its type or command determines what happens.
- <section>: A section groups content with a shared topic.
- href: Href is the URL to a related resource or destination.
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.
A quick keyboard check: Press Tab to move forward, Shift+Tab to go back, and Enter or Space to activate controls when appropriate. Watch where focus goes. If you cannot tell which control is active, the interface needs improvement.
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.
- ARIA changes what assistive technology is told; it does not automatically add keyboard controls, visual styling, or JavaScript behavior.
Key Takeaways
- Tabindex changes whether and how an element participates in keyboard focus.
- tabindex: Tabindex affects sequential keyboard focus; positive values are usually a poor choice.
- A meaningful HTML element is usually a stronger starting point than adding an ARIA role to a generic div. Also check what happens using only the keyboard.