Skip to content

useKeyWithClickEvents (HTML)

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

Enforce elements with a click event handler to also have at least one keyboard event handler.

Coding for the keyboard is important for users with physical disabilities who cannot use a mouse, AT compatibility, and screen reader users. This rule checks that interactive elements with an onclick attribute also include at least one of onkeydown, onkeyup, or onkeypress.

This does not apply to elements that are inherently keyboard-accessible (such as <button>, <input>, <select>, <textarea>, or <a> with an href attribute) or elements that are hidden from assistive technologies.

<div onclick="handleClick()"></div>
code-block.html:1:1 lint/a11y/useKeyWithClickEvents ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Elements with onclick must also include at least one keyboard handler: onkeydown, onkeyup, or onkeypress.

> 1 │ <div onclick="handleClick()"></div>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │

Actions triggered using mouse events should have corresponding keyboard events to account for keyboard-only navigation.

<div onclick="handleClick()" onkeydown="handleKeyDown()"></div>
<div onclick="handleClick()" onkeyup="handleKeyUp()"></div>
<div onclick="handleClick()" onkeypress="handleKeyPress()"></div>
<button onclick="handleClick()">Submit</button>
<input onclick="handleClick()" />