HTML Tips: When to Use <button>, <a>, and role="button" Without Breaking Accessibility

December 5, 2026

Choosing between <button>, <a href>, and role="button" is mostly about one question: what does the control do? Native elements already carry the semantics, keyboard behavior, focus behavior, and browser features users expect. The wrong choice often looks fine visually, but breaks keyboard navigation, form submission, or screen-reader output.

web accessibility keyboard

Start with these 5 decision rules

  1. It performs an action on the same page? Use <button>. Examples: open a menu, show a dialog, copy text, add to cart.
  2. It changes the URL or navigates to another resource? Use <a href="...">. Examples: go to a page, jump to a heading, open a PDF.
  3. It submits or resets a form? Use a real <button type="submit"> or type="reset" inside the form.
  4. You have a non-button element that must behave like a button? Add role="button", tabindex="0", full keyboard support, visible focus, and disabled handling — but prefer replacing it with a native button.
  5. Do not put role="button" on a navigational link. <a href="/checkout" role="button"> may look like a button, but it lies about its semantics and removes the link announcement users need.
html code editor

Use <button> for actions and form behavior

A native button is the safest choice for anything that triggers an action. It is automatically focusable, it announces as a button, and it supports both Enter and Space from the keyboard. It also participates in forms depending on its type.

Common button patterns

<button type="button" id="menu-button" aria-expanded="false" aria-controls="menu">
  Account
</button>

<div id="menu" hidden>
  <!-- menu items -->
</div>

Use type="button" when the button only runs JavaScript. Otherwise, a button inside a form defaults to type="submit", which can accidentally submit the form.

<form action="/subscribe" method="post">
  <label>
    Email
    <input type="email" name="email" required>
  </label>

  <button type="submit">Subscribe</button>
  <button type="reset">Reset</button>
</form>

For an icon-only button, add an accessible name. The simplest version is visually hidden text:

<button type="button" aria-label="Close dialog">
  <svg aria-hidden="true" focusable="false">...</svg>
</button>

Disabled buttons are removed from the tab order and announced as disabled:

<button type="submit" disabled>
  Save changes
</button>

The pitfall: disabled buttons can be hard to understand because the user cannot focus them to hear why they are unavailable. For complex forms, it is often better to keep the button enabled and show validation errors on activation.

Use <a href> for navigation

Links take the user somewhere: another page, another route, a downloadable file, or a fragment on the same page. A real link needs a non-empty href. Without href, an <a> is not normally focusable and does not get link semantics.

<a href="/pricing">View pricing</a>

<a href="#shipping">Jump to shipping details</a>

<a href="/manual.pdf" download>
  Download manual (PDF)
</a>

Links respond to Enter by default. They also support browser capabilities that buttons do not: open in a new tab, copy link address, bookmark, share, Ctrl/Cmd-click, and middle-click. If users may want to open the destination in a new tab, a link is usually the right control.

For same-page anchors, make sure the target can receive focus or is naturally reachable by screen readers. A common fix is to put the id on a heading or a focusable section:

<a href="#comments">Skip to comments</a>

<section id="comments" tabindex="-1" aria-labelledby="comments-title">
  <h2 id="comments-title">Comments</h2>
</section>

The <a href role="button"> anti-pattern

This is tempting because CSS button styles are already applied to the link:

<!-- Avoid: it navigates, but says it is a button -->
<a href="/checkout" role="button">
  Checkout
</a>

Do not do that for navigation. Screen-reader users hear a button, keyboard users expect button activation behavior, and mouse users still get link features such as opening in a new tab. The semantics and browser behavior no longer match.

If it goes to /checkout, use a link and style it like a button:

<a class="btn" href="/checkout">
  Checkout
</a>

Visual styling does not determine HTML semantics. A link can look like a button and still be announced as a link.

Use role="button" only as a repair, not a habit

role="button" adds button semantics to an element that is not already a button. It does not add button behavior. A <span> or <div> with role="button" is not automatically focusable, does not handle Space, does not submit forms, and does not become a native clickable control.

A minimum accessible implementation needs all of the following:

  • tabindex="0" so it is in the normal tab order.
  • An accessible name from text content, aria-label, or aria-labelledby.
  • Keyboard handling for Enter and Space.
  • Visible focus styling, preferably :focus-visible.
  • Correct disabled behavior with either removal from tab order or aria-disabled="true".
  • Guarding against duplicate activation.
<span
  role="button"
  tabindex="0"
  id="like-trigger"
  aria-pressed="false"
>
  Like
</span>
const trigger = document.querySelector('#like-trigger');

function activate() {
  if (trigger.getAttribute('aria-disabled') === 'true') return;

  const pressed = trigger.getAttribute('aria-pressed') === 'true';
  trigger.setAttribute('aria-pressed', String(!pressed));
}

trigger.addEventListener('click', activate);

trigger.addEventListener('keydown', (event) => {
  if (event.key !== 'Enter' && event.key !== ' ' && event.key !== 'Spacebar') return;

  event.preventDefault();

  if (event.repeat) return;

  if (event.key === 'Enter') {
    activate();
  }
});

trigger.addEventListener('keyup', (event) => {
  if (event.key !== ' ' && event.key !== 'Spacebar') return;

  event.preventDefault();

  if (event.repeat) return;

  activate();
});

Space is handled on keyup to mirror native buttons; pressing Space and moving away before release should not activate the control. Calling preventDefault() stops the page from scrolling. The event.repeat guard prevents repeated activation while the key is held.

Add visible keyboard focus:

[role='button']:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

For a disabled ARIA button, choose one model. Remove it from focus if it is truly unavailable:

<span role="button" aria-disabled="true" class="is-disabled">
  Save
</span>

If you keep it focusable so assistive technology users can discover why it is disabled, keep tabindex="0", set aria-disabled="true", and block activation in your handler. Do not rely only on gray CSS.

Even after all that work, an ARIA button still does not gain native form participation. If the control submits a form, use a real submit button.

Quick comparison

Control Semantics Focusable Enter / Space Form participation Browser link features Screen-reader announcement
<button type="button"> Button Yes, unless disabled Enter and Space activate No submit behavior No Button, plus name and state
<button type="submit"> Button Yes, unless disabled Enter and Space submit Submits associated form No Submit button or button, plus name
<a href> Link Yes Enter navigates; Space has native scrolling behavior No New tab, copy link, bookmark, modified click Link, plus name
<span role="button" tabindex="0"> Exposed as button Only because of tabindex Must be implemented with JavaScript No native form behavior No Button, but behavior depends on your code

Copyable decision checklist

  • Does it navigate? Use <a href>.
  • Does it open, close, toggle, copy, delete, save, or run JavaScript? Use <button type="button">.
  • Does it submit a form? Use <button type="submit">.
  • Does it reset a form? Use <button type="reset">.
  • Does it only look like a button but navigates? Keep the link and change the CSS.
  • Can you change the markup to a native button? Do that before using ARIA.
  • Stuck with non-native markup? Add role="button", tabindex="0", Enter/Space handling, focus styles, an accessible name, and disabled logic.

Common mistakes

  • Using <div onclick> without semantics, focus, or keyboard handlers.
  • Adding role="button" to an <a href> that navigates.
  • Forgetting type="button", causing a JavaScript control to submit the form.
  • Using <a href="#"> for actions and adding history entries.
  • Handling click but not Enter and Space.
  • Removing focus outlines without adding a visible replacement.
  • Using only color or opacity to communicate a disabled state.
  • Expecting role="button" to provide native button or form behavior.

The short version is simple: links go places, buttons do things, and ARIA only patches semantics when native HTML cannot be used. Start from that rule, and most accessibility problems disappear before they reach the browser.