Tabindex Accessibility Cheat Sheet
This cheat sheet helps you apply tabindex properly for keyboard accessibility, aligning with best practices for semantic HTML, ARIA, and accessible design.
π’ Tabindex Values & Their Meaning
tabindex Value
Description
β Use When
β Avoid When
tabindex="0"
Includes an element in the natural tab order
For custom elements like <div role="button"> or accessible widgets
On elements already natively focusable like <a>, <button>
tabindex="-1"
Focusable only via JavaScript, not by tabbing
For programmatic focus (e.g., modals, alerts, skip links)
If keyboard users need to reach it with Tab
tabindex="1+"
Overrides natural order with custom tab flow (discouraged)
Very specific UI needs (e.g., legacy systems or game-like interfaces)
Most cases β it disrupts expected navigation
β Elements That Donβt Need tabindex="0"
tabindex="0"<a href="...">
Already keyboard-focusable
<button>
Already in tab order
<input>
Naturally focusable
<select>
Naturally focusable
<textarea>
Naturally focusable
<summary>
Focusable by default in <details>
β
Elements That MAY Need tabindex="0" (When Interactive)
tabindex="0" (When Interactive)<div>
If used as button, link, tab, etc. with appropriate ARIA role
<span>
Same as <div>, when made interactive
<li>
When part of custom components like tabs or menus
<img>
Only when interactive (e.g., image gallery navigation)
<svg>
For clickable icons or custom controls
<section>
When used as a focusable landmark for keyboard navigation
<article>
Same as above β use tabindex="0" only for meaningful keyboard stops
π‘ Best Practices
Never use positive
tabindex(tabindex="1"or more) unless absolutely required.Use
tabindex="-1"to trap focus temporarily (e.g., in modals).Combine
tabindex="0"with proper roles (role="button",role="link") and keyboard support (Enter,Spacehandlers).Avoid cluttering the page with unnecessary focus targets β focus should only land on meaningful elements.
β
Example: Accessible Custom Button
Last updated