Skip to content

noAutofocus (HTML)

biome.json
{
"linter": {
"rules": {
"a11y": {
"noAutofocus": "error"
}
}
}
}

Enforce that the autofocus attribute is not used on elements.

Autofocusing elements can cause usability issues for sighted and non-sighted users, alike. However, the autofocus attribute is allowed on elements inside a dialog element or elements with a popover attribute, as these are modal contexts where autofocus is expected.

<input autofocus />
code-block.html:1:8 lint/a11y/noAutofocus  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

βœ– This element uses the autofocus attribute outside an allowed modal context.

> 1 β”‚ <input autofocus />
β”‚ ^^^^^^^^^
2 β”‚

β„Ή Autofocusing elements can disrupt navigation and confuse screen reader and keyboard users.

β„Ή Unsafe fix: Remove the autofocus attribute.

1 β”‚ <inputΒ·autofocusΒ·/>
β”‚ ----------
<input autofocus="true" />
code-block.html:1:8 lint/a11y/noAutofocus  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

βœ– This element uses the autofocus attribute outside an allowed modal context.

> 1 β”‚ <input autofocus="true" />
β”‚ ^^^^^^^^^^^^^^^^
2 β”‚

β„Ή Autofocusing elements can disrupt navigation and confuse screen reader and keyboard users.

β„Ή Unsafe fix: Remove the autofocus attribute.

1 β”‚ <inputΒ·autofocus="true"Β·/>
β”‚ -----------------
<textarea autofocus>content</textarea>
code-block.html:1:11 lint/a11y/noAutofocus  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

βœ– This element uses the autofocus attribute outside an allowed modal context.

> 1 β”‚ <textarea autofocus>content</textarea>
β”‚ ^^^^^^^^^
2 β”‚

β„Ή Autofocusing elements can disrupt navigation and confuse screen reader and keyboard users.

β„Ή Unsafe fix: Remove the autofocus attribute.

1 β”‚ <textareaΒ·autofocus>content</textarea>
β”‚ ---------
<input />
<div popover><input autofocus /></div>
<dialog><input autofocus /></dialog>