Course contentsShow
← Web Development
Lesson 1045 of 2,98219. Keyboard Navigation and FocusFree lesson

tabindex='0' for Custom Interactive Elements

Making non-interactive elements keyboard accessible by adding them to the natural tab order.

tabindex='0' for Custom Interactive Elements

You'll learn how to make custom interactive elements keyboard-accessible by adding them to the natural tab order without disrupting the flow of navigation.

The Core Problem

By default, only certain HTML elements (like buttons, links, and form inputs) are keyboard-accessible—they can receive focus when a user presses the Tab key. But what if you've built a custom interactive component, like a clickable card or a custom dropdown trigger using a <div> or <span>? These elements won't respond to keyboard navigation at all, locking out keyboard users.

Enter tabindex='0'

When you add tabindex="0" to a non-interactive element, you're essentially telling the browser: "Treat this element as if it were naturally focusable, and insert it into the tab order exactly where it appears in the document flow."

Think of it like adding someone's name to a waiting list based on their arrival time, not cutting the line or jumping ahead.

<div class="custom-button" tabindex="0">
  Click or press Enter
</div>

This <div> now receives focus when users tab through the page, appearing in the natural order among other focusable elements.

When to Use It

Use tabindex="0" when you've created interactive elements that users need to activate with the keyboard—custom controls, expandable panels, or interactive cards. This is your most common tabindex value because it respects the document's natural flow.

Important: Adding tabindex="0" only makes the element focusable—you still need to add keyboard event listeners (like for Enter or Space keys) to make it truly functional.

Key Takeaway: tabindex="0" adds non-interactive elements to the natural tab order, making them keyboard-accessible without disrupting the document flow—essential for custom interactive components.