Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP C C++ C# AWS W3.CSS HOW TO BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST TOOLS MATH

HTML Tutorial

HTML HOME HTML Introduction HTML Editors HTML Basic HTML Elements HTML Attributes HTML Headings HTML Paragraphs HTML Styles HTML Project I HTML Formatting HTML Quotations HTML Comments HTML Colors HTML CSS HTML Project II HTML Links HTML Images HTML Favicon HTML Page Title HTML Tables HTML Lists HTML Project III HTML Block & Inline HTML Div HTML Classes HTML Id HTML Project IV HTML Buttons HTML Iframes HTML JavaScript HTML File Paths HTML Head HTML Layout HTML Responsive HTML Project V HTML Computercode HTML Semantics HTML Project VI HTML Dialog HTML Style Guide HTML Entities HTML Symbols HTML Emojis HTML Charsets HTML URL Encode HTML vs. XHTML

HTML Forms

HTML Forms HTML Form Attributes HTML Form Elements HTML Input Types HTML Input Attributes Input Form Attributes HTML Project VII

HTML Graphics

HTML Canvas HTML SVG

HTML Media

HTML Media HTML Video HTML Audio HTML YouTube HTML Project VIII

Web Accessibility

Web Accessibility ARIA Attributes Keyboard Focus and tabindex Landmarks Skip Links Color Contrast

Web APIs

Web APIs Geolocation API Drag and Drop API Popover API Web Storage API Web Workers API Server-Sent Events API

HTML Cert

HTML Certificate

HTML Examples

HTML Examples HTML Videos HTML Editor HTML Quiz HTML Exercises HTML Challenges HTML Projects HTML Website HTML Syllabus HTML Study Plan HTML Interview Prep HTML Summary

HTML References

HTML Tag List HTML Attributes HTML Global Attributes HTML Browser Support HTML Event Attributes HTML Colors HTML Canvas HTML Audio/Video HTML Doctypes HTML Character Sets HTML URL Encode HTML Language Codes HTML Country Codes HTTP Status Codes HTTP Request Methods PX to EM Converter Keyboard Shortcuts

Web Accessibility - Keyboard Focus and tabindex


Share

Keyboard Focus and tabindex

Many people move around a page with the keyboard only. They press Tab to go to the next link, button, or form field, and Shift + Tab to go back. The element they are on has focus.

Links, buttons, and form fields can get focus by default. Other elements, like <div> and <span>, cannot.


The tabindex Attribute

The tabindex attribute controls whether an element can get focus.

Value What it does
tabindex="0" The element can get focus with Tab, in the normal page order
tabindex="-1" The element can get focus only with JavaScript (element.focus()), not with Tab
tabindex="1" or higher Jumps ahead in the Tab order. Avoid this: it makes the order confusing

Example

<!-- Can be reached with Tab -->
<div tabindex="0">Custom widget</div>

<!-- Can be focused by script, for example after an error -->
<div tabindex="-1" id="errorTitle">Please fix error</div>

Tip: If you need tabindex="0" to make something clickable, ask yourself if it should be a button instead.



Always Show where Focus is

Users must always see which element has focus. Never remove the focus outline without adding a new one:

Example

/* Do NOT do this */
button:focus {
  outline: none;
}

/* Do this */
button:focus-visible {
  outline: 3px solid #1a73e8;
  outline-offset: 2px;
}

The CSS :focus-visible pseudo-class shows the outline when the user is using the keyboard, but not when they click with a mouse.


Keep a Logical Order

The Tab order follows the order of the HTML. Write your HTML in the same order people read the page, and do not use CSS to move things far from where they are in the code.


Free account

Track your progress

XP earned 0 Day streak 0 Spaces 0 League —

New

Learn in Adventure Mode W3Schools Adventure App

Coding fundamentals as bite-sized lessons and challenges.

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by W3Schools. All Rights Reserved. W3Schools is Powered by W3.CSS.