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>