الانتقال إلى المحتوى
FrontendAccessibility· 6 دقائق للقراءة

ARIA Doesn't Make a div a Button: Start with Semantic HTML

A role changes what assistive technology hears, not what the element does. A real button does both.

ReadIn

مقال كل يوم يفرق معاك

21 نوفمبر 2026
  • كاتب موثّق
  • WCAG 2.2
محتويات المقال

A keyboard-only user writes to support: she can fill in the whole checkout form, but she can't place the order. The "Place order" control is a div with a click handler. Months ago a review found that screen readers read it as plain text, so someone added role="button". Screen readers started saying "button", the ticket was closed, and nobody tried the page without a mouse. Tab jumps straight past the control.

The common misconception

The belief: adding role="button" and a click handler to a div makes it as accessible as a real button.

It's a reasonable conclusion, because the role really does change something. Rendered in headless Chromium, the accessibility tree shows the div and a real <button> as the same entry: button "Place order". The click handler works with a mouse and with a tap. And MDN describes ARIA as a set of roles and attributes that make web content more accessible, so adding one feels like adding accessibility. If you only check what a screen reader announces, the job looks done.

What actually happens

ARIA edits the accessibility tree, nothing else

Next to the DOM, the browser builds an : for every element that matters, a role, an and its states. Screen readers and other assistive technologies read that tree. ARIA attributes overwrite entries in it, and that's all they do. The ARIA Authoring Practices Guide says it directly: unlike HTML input elements, ARIA roles don't make browsers provide keyboard behaviors or styling.

So the div and the button look identical to a screen reader. The difference is entirely in what they do.

What the div is still missing

We put a div with role="button" and a real button on the same page in headless Chromium and used only the keyboard:

  • Focus: Tab skipped the div completely. It only joined the tab order after we added tabindex="0".
  • Activation: even when focused, Enter and Space didn't fire its click handler. MDN explains why: a native button fires click for Space and Enter, but on any other element click comes only from the pointer, even with the role.
  • Space: instead of activating anything, Space scrolled the page down by most of a screen (525px in our 600px-high viewport).
  • Disabled: a disabled <button> can't be focused or pressed. A div has no disabled attribute; aria-disabled="true" only announces a state and blocks nothing.

A role is a promise

The APG calls this its first principle: a role is a promise. role="button" promises that you also wrote the script for the keyboard interactions people expect from a button. Breaking it, the guide says, is similar to making a "Place Order" button that abandons an order and empties the shopping cart.

Here's what keeping that promise takes, for the keyboard alone:

JavaScript fake-button.js
const fake = document.querySelector("#place-order");fake.tabIndex = 0; // join the tab orderfake.addEventListener("keydown", (event) => {  if (event.key === "Enter") fake.click();  if (event.key === " ") event.preventDefault(); // don't scroll});fake.addEventListener("keyup", (event) => {  if (event.key === " ") fake.click(); // like a native button});

In Chromium, a native button fires click on key down for Enter and on key up for Space, and this script copies that timing. It still has no disabled support and no form behavior, and every team that fakes a button writes its own slightly different copy.

Links have the same trap in reverse. MDN points out that people expect a button to respond to Space or Enter but a link only to Enter, so a link dressed up with role="button" needs a Space handler too. Choose the element by what it does: a button performs an action on the page, and a link takes the user somewhere.

The first rule of ARIA

MDN quotes the first rule of ARIA use: "If you can use a native HTML element or attribute with the semantics and behavior you require already built in, instead of re-purposing an element and adding an ARIA role, state or property to make it accessible, then do so." WCAG 2.2 points the same way. Its Understanding document for 4.1.2 Name, Role, Value (Level A) notes that standard HTML controls already meet the criterion when used according to the specification; custom controls need extra work. And a control that can't be operated from the keyboard fails 2.1.1 Keyboard, also Level A.

For the checkout, the fix is one element:

HTML checkout.html
<!-- Announced as a button, but Tab skips it     and Enter or Space does nothing --><div class="btn" role="button" onclick="placeOrder()">  Place order</div>
What users need<div role="button"><button type="button">
Announced as a buttonYesYes
Reachable with TabOnly with tabindex="0"Yes
Enter and Space fire clickOnly with your own key handlersYes
Space doesn't scroll the pageOnly with preventDefault()Yes
disabled blocks focus and clicksNo, you script it yourselfYes

How to apply it in your project

  1. Find the fakesSearch your templates for role="button", for click handlers on div and span, and for cursor: pointer on elements that aren't links or buttons.
  2. Put the mouse awayTab through every flow you ship. Each control must be reachable, show where focus is, and work with Enter and Space for buttons or Enter for links.
  3. Swap the element, then restyleUse <button type="button"> for actions and <a href> for navigation. Move the look into CSS, so the element keeps its built-in behavior.
  4. Keep ARIA for what HTML can't sayAdd ARIA on top of native elements only for meaning HTML lacks, such as aria-pressed on a toggle button or aria-expanded on a button that opens a panel.

Key takeaways

  • ARIA changes only the accessibility tree: role, name and state. It adds no behavior.
  • role="button" on a div leaves out focus, Enter and Space activation and disabled; you'd have to script each one.
  • A native <button type="button"> brings all of it, and standard HTML controls meet WCAG 4.1.2 when used as specified.
  • Follow the first rule of ARIA: use the native element, and add ARIA only for what HTML can't express.
  • Test with the keyboard alone: a control that announces "button" proves nothing about whether it works.

📚 المصادر

  1. Read Me First — ARIA Authoring Practices Guide (W3C WAI)
  2. ARIA: button role — MDN
  3. Understanding SC 4.1.2: Name, Role, Value — WCAG 2.2 (W3C WAI)
  4. HTML: A good basis for accessibility — MDN
  5. ARIA — MDN

التعليقات (0)