We'd like to set Google Analytics cookies to learn how people use the Knowledge Base, so we can improve it. We set them only if you accept.

Skip to main content
Digital Accessibility Knowledge Base

element-not-activated-by-keyboard

Web validation

Interactive content must be operable using the keyboard.

Keyboard users move to a control with the Tab key, and activate it with Enter or Space. Native controls, such as <button>, handle these keys for you. A custom control built from a generic element, such as a <div> or a <span>, doesn't: it reacts only to the events your script listens for.

When a custom control can receive focus but listens only for mouse clicks, keyboard users can reach it, but pressing Enter or Space does nothing. They can see the control and focus it, but they can't use it.

Evinced reports this issue when an element can be activated with a mouse click, but not with the Enter or Space key.

To fix the issue:

  • If possible, replace the custom element with the equivalent native HTML element. Native elements provide built-in keyboard support, and usually need only a click event handler.
  • If a native element can't be used, add keyboard event listeners that trigger the same action as a mouse click when the Enter or Space key is pressed.

Pass Patterns

Native button

A native <button> activates with Enter and Space, so a click handler is all it needs.

HTML
<button type="button" onclick="addToCart()">Add to cart</button>

Custom button with keyboard handlers

The custom button activates on Enter when the key goes down, and on Space when the key comes up, the same as a native button. Pressing Space doesn't scroll the page, because its default action is cancelled.

HTML
<div role="button" tabindex="0" id="add-to-cart">Add to cart</div>


<script>
    const button = document.getElementById("add-to-cart");


    button.addEventListener("click", addToCart);


    button.addEventListener("keydown", (event) => {
        if (event.key === "Enter") {
            event.preventDefault();
            addToCart();
        }
        if (event.key === " ") {
            event.preventDefault();
        }
    });


    button.addEventListener("keyup", (event) => {
        if (event.key === " ") {
            addToCart();
        }
    });
</script>

Fail Patterns

Focusable custom button with only a click handler

The <div> has a role and tabindex="0", so keyboard users can reach it, but it listens only for clicks, so Enter and Space do nothing.

HTML
<div role="button" tabindex="0" onclick="addToCart()">Add to cart</div>

Focusable icon with only a click handler

The star can receive focus, but nothing happens when keyboard users press Enter or Space on it.

HTML
<span class="favorite-icon" tabindex="0" onclick="toggleFavorite()" aria-label="Add to favorites">☆</span>

WCAG techniques

Sufficient techniques

Failure techniques

Try It Yourself

Using a keyboard

  1. Open the page in a browser, without using a screen reader.
  2. Press the Tab key until the control has focus.
  3. Press Enter. If nothing happens, press Space.

Expected results: The control performs the same action as when it's clicked with a mouse.

Actual results: The control receives focus, but nothing happens when Enter or Space is pressed.

Inspecting the browser dev-tools

  1. In your browser's dev tools, select the control and open its event listeners panel.
  2. Check which events the control, or one of its ancestors, listens for.

Expected results: The control is a native element, or it has a keydown or keyup listener that handles Enter and Space.

Actual results: The control has a click listener, but no listener for keyboard events.

FAQ

How does this issue relate to 2.1.1 Keyboard?

SC 2.1.1 requires all functionality to be operable through a keyboard interface. When a control can be activated only with a mouse, its function isn't available to people who use a keyboard, so it fails the criterion.

Why is this issue marked as Critical?

For people who use only a keyboard, or a switch device that emulates one, a control that ignores Enter and Space is a complete barrier. If it submits a form, opens a menu, or adds an item to a cart, they can't complete the task at all.

Which keys should activate the control?

It depends on the control's role. Buttons activate with both Enter and Space, and links activate with Enter only. Other widgets, such as checkboxes, follow the keyboard conventions of their pattern in the ARIA Authoring Practices Guide.

Why can screen reader users sometimes activate the control anyway?

In their default reading mode, screen readers turn Enter and Space into a click on the element, and voice input software also activates controls with a click. These users can often activate the control, but people who use only a keyboard can't, so test without a screen reader running.

Standards and Regulations

StandardSuccess CriterionReference
WCAG 2.22.1.1 Keyboard (A)All functionality of the content is operable through a keyboard interface without requiring specific timings for individual keystrokes, except where the underlying function requires input that depends on the path of the user's movement and not just the endpoints.
EN 301 5499.2.1.1 KeyboardSame as the WCAG text.
Section 5081194.21(a)When software is designed to run on a system that has a keyboard, product functions shall be executable from a keyboard where the function itself or the result of performing a function can be discerned textually.
508 Trusted Tester2.1.1-keyboard-access, 4.AAll functionality can be accessed and executed using only the keyboard.

Personas impacted by this issue

Learn More