tabindex global attribute indicates that its element can be focused, and where it participates in sequential keyboard navigation (usually with the Tab key, hence the name).

The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.

It accepts an integer as a value, with different results depending on the integer's value:

  • A negative value (usually tabindex="-1" ) means that the element is not reachable via sequential keyboard navigation, but could be focused with Javascript or visually by clicking with the mouse. It's mostly useful to create accessible widgets with JavaScript.

    A negative value is useful when you have off-screen content that appears on a specific event. The user won't be able to focus any element with a negative tabindex using the keyboard, but a script can do so by calling the focus() method .

  • tabindex="0" means that the element should be focusable in sequential keyboard navigation, after any positive tabindex values and its order is defined by the document's source order.
  • A positive value means the element should be focusable in sequential keyboard navigation, with its order defined by the value of the number. That is, tabindex="4" is focused before tabindex="5" and tabindex="0" , but after tabindex="3" . If multiple elements share the same positive tabindex value, their order relative to each other follows their position in the document source. The maximum value for tabindex is 32767. If not specified, it takes the default value 0.

    避免使用 tabindex values greater than 0. Doing so makes it difficult for people who rely on assistive technology to navigate and operate page content. Instead, write the document with the elements in a logical sequence.

If you set the tabindex attribute on a <div> , then its child content cannot be scrolled with the arrow keys unless you set tabindex on the content, too. Check out this fiddle to understand the scrolling effects of tabindex .

可访问性关注

Avoid using the tabindex attribute in conjunction with non- interactive content to make something intended to be interactive focusable by keyboard input. An example of this would be using a <div> element to describe a button, instead of the <button> 元素。

Interactive components authored using non-interactive elements are not be listed in the accessibility tree . This prevents assistive technology from being able to navigate to and manipulate those components. The content should be semantically described using interactive elements ( <a> , <button> , <details> , <input> , <select> , <textarea> , etc.) instead. These elements have built-in roles and states that communicate status to the accessibility that would otherwise have to be managed by ARIA .

规范

规范 状态 注释
HTML 实时标准
The definition of 'tabindex' in that specification.
实时标准 No change from latest snapshot, HTML 5.1 .
HTML 5.1
The definition of 'tabindex' in that specification.
推荐 快照 HTML 实时标准 , no change from HTML5 .
HTML5
The definition of 'tabindex' in that specification.
推荐 快照 HTML 实时标准 . From HTML 4.01 Specification , the attribute is now supported on all elements (global attributes).
HTML 4.01 Specification
The definition of 'tabindex' in that specification.
推荐 Only supported on <a> , <area> , <button> , <input> , <object> , <select> ,和 <textarea> .

浏览器兼容性

更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
tabindex Chrome 完整支持 Yes Edge 完整支持 12 Firefox 完整支持 Yes IE 完整支持 Yes Opera 完整支持 Yes Safari 完整支持 Yes WebView Android 完整支持 Yes Chrome Android 完整支持 Yes Firefox Android 完整支持 Yes Opera Android 完整支持 Yes Safari iOS 完整支持 Yes Samsung Internet Android 完整支持 Yes

图例

完整支持

完整支持

另请参阅

元数据

  • 最后修改:
  1. HTML
  2. 教程:
  3. HTML 基础
  4. HTML 介绍
    1. Introduction to HTML overview
    2. Getting started with HTML
    3. What's in the head? Metadata in HTML
    4. HTML text fundamentals
    5. Creating hyperlinks
    6. Advanced text formatting
    7. Document and website structure
    8. Debugging HTML
    9. Assessment: Marking up a letter
    10. Assessment: Structuring a page of content
  5. 多媒体和嵌入
    1. Multimedia and embedding overview
    2. Images in HTML
    3. Video and audio content
    4. From object to iframe — other embedding technologies
    5. Adding vector graphics to the Web
    6. Responsive images
    7. Assessment: Mozilla splash page
  6. 参考:
  7. HTML 元素
    1. <a>
    2. <abbr>
    3. <acronym>
    4. <address>
    5. <applet>
    6. <area>
    7. <article>
    8. <aside>
    9. <audio>
    10. <b>
    11. <base>
    12. <basefont>
    13. <bdi>
    14. <bdo>
    15. <bgsound>
    16. <big>
    17. <blink>
    18. <blockquote>
    19. <body>
    20. <br>
    21. <button>
    22. <canvas>
    23. <caption>
    24. <center>
    25. <cite>
    26. <code>
    27. <col>
    28. <colgroup>
    29. <command>
    30. <content>
    31. <data>
    32. <datalist>
    33. <dd>
    34. <del>
    35. <details>
    36. <dfn>
    37. <dialog>
    38. <dir>
    39. <div>
    40. <dl>
    41. <dt>
    42. <element>
    43. <em>
    44. <embed>
    45. <fieldset>
    46. <figcaption>
    47. <figure>
    48. <font>
    49. <footer>
    50. <form>
    51. <frame>
    52. <frameset>
    53. <h1>
    54. <head>
    55. <header>
    56. <hgroup>
    57. <hr>
    58. <html>
    59. <i>
    60. <iframe>
    61. <image>
    62. <img>
    63. <input>
    64. <ins>
    65. <isindex>
    66. <kbd>
    67. <keygen>
    68. <label>
    69. <legend>
    70. <li>
    71. <link>
    72. <listing>
    73. <main>
    74. <map>
    75. <mark>
    76. <marquee>
    77. <menu>
    78. <menuitem>
    79. <meta>
    80. <meter>
    81. <multicol>
    82. <nav>
    83. <nextid>
    84. <nobr>
    85. <noembed>
    86. <noframes>
    87. <noscript>
    88. <object>
    89. <ol>
    90. <optgroup>
    91. <option>
    92. <output>
    93. <p>
    94. <param>
    95. <picture>
    96. <plaintext>
    97. <pre>
    98. <progress>
    99. <q>
    100. <rb>
    101. <rp>
    102. <rt>
    103. <rtc>
    104. <ruby>
    105. <s>
    106. <samp>
    107. <script>
    108. <section>
    109. <select>
    110. <shadow>
    111. <slot>
    112. <small>
    113. <source>
    114. <spacer>
    115. <span>
    116. <strike>
    117. <strong>
    118. <style>
    119. <sub>
    120. <summary>
    121. <sup>
    122. <table>
    123. <tbody>
    124. <td>
    125. <template>
    126. <textarea>
    127. <tfoot>
    128. <th>
    129. <thead>
    130. <time>
    131. <title>
    132. <tr>
    133. <track>
    134. <tt>
    135. <u>
    136. <ul>
    137. <var>
    138. <video>
    139. <wbr>
    140. <xmp>
  8. 全局属性
    1. accesskey
    2. autocapitalize
    3. class
    4. contenteditable
    5. contextmenu
    6. data-*
    7. dir
    8. draggable
    9. dropzone
    10. hidden
    11. id
    12. inputmode
    13. is
    14. itemid
    15. itemprop
    16. itemref
    17. itemscope
    18. itemtype
    19. lang
    20. part
    21. slot
    22. spellcheck
    23. style
    24. tabindex
    25. title
    26. translate
    27. x-ms-acceleratorkey
    28. x-ms-format-detection
  9. <input> 类型
    1. <input type="button">
    2. <input type="checkbox">
    3. <input type="color">
    4. <input type="date">
    5. <input type="datetime">
    6. <input type="datetime-local">
    7. <input type="email">
    8. <input type="file">
    9. <input type="hidden">
    10. <input type="image">
    11. <input type="month">
    12. <input type="number">
    13. <input type="password">
    14. <input type="radio">
    15. <input type="range">
    16. <input type="reset">
    17. <input type="search">
    18. <input type="submit">
    19. <input type="tel">
    20. <input type="text">
    21. <input type="time">
    22. <input type="url">
    23. <input type="week">
  10. 文档编制:
  11. 有用清单
  12. All pages index
  13. Pages tagged "HTML"
  14. 贡献
    1. HTML 文档状态
    2. MDN 工程

版权所有  © 2014-2026 乐数软件    

工业和信息化部: 粤ICP备14079481号-1