HTML tabindex

Created By: chatGPT

The tabindex attribute in HTML is used to control the order in which elements receive focus when the user navigates through a page using the Tab key. It can also define elements that can be focused on when using a pointing device like a mouse. This attribute can take three different types of values: a positive integer, zero, or a negative integer.
<button tabindex="1">First Button</button>
<input type="text" tabindex="2" placeholder="Second Input">
<a href="#" tabindex="3">Link Item</a>
<div tabindex="0">Focusable Div (using default order)</div>
Setting tabindex to a positive integer means that the element can be focused and is part of the explicit tab order specified by the value. By default, elements with a positive tabindex will be focused in the order of ascending tabindex values. For example, a button with tabindex=1 will be focused before an input with tabindex=2.
<button tabindex="1">First Button</button>
<input type="text" tabindex="2" placeholder="Second Input">
Setting tabindex to zero (0) makes the element focusable and includes it in the natural tab order of the page. This means that it will follow the sequence of other focusable elements in the DOM, without explicitly specifying its priority over other elements.
<div tabindex="0">Focusable Div (natural order)</div>
On the other hand, setting tabindex to a negative integer (usually -1) makes an element focusable, but it will not be reachable via the Tab key. It can still be focused programmatically, typically using JavaScript, for instance, when responding to a click event.
<button tabindex="-1">Cannot Tab to this Button</button>
Using tabindex effectively enhances the user experience by making navigation more intuitive, especially for keyboard users. It's essential to use it cautiously to avoid interrupting the natural flow of tabbing through elements. Misusing this attribute can lead to confusion or accessibility issues.
<form>
    <button tabindex="1">Submit</button>
    <input type="text" tabindex="3" placeholder="Name">
    <button tabindex="2">Cancel</button>
</form>
Introduction And SetupHeadTitleMetaLinkStyleScriptBodyHeaderNavSectionArticleAsideFooterH1H2H3H4H5H6PBlockquoteOlUlLiAImgTableTrTdThCaptionFormInputTextareaButtonSelectOptionLabelFieldsetLegendCanvasSvgVideoAudioEmbedObjectIframeDivSpanStrongEmSmallSubSupMarkCiteDfnAbbrTimeDataVarCodeKbdSampQCiteRubyRbRtRtcRpBdiBdoWbrDatalistOutputProgressMeterDetailsSummaryTemplatePictureSourceTrackMeta CharsetMeta NameMeta ContentMeta ViewportMeta Http EquivLink RelLink HrefScript SrcScript AsyncStyle TypeBody OnloadIdClassStyleSrcHrefAltTitleValueNameTypePlaceholderDisabledReadonlyCheckedActionMethodForMaxlengthMinlengthAutocompleteTargetRelData *WidthHeightLangTabindexAria *DraggableHiddenAutofocusRequiredDownload