How accessible is your website?Start free check
WCAG 4.1.2Level ARobust

Button vs. Link: When to Use Which

Also called: Link or button, a vs. button, Buttons and links

Definition

Button vs. link is the rule for choosing the right HTML element: a link (<a href>) navigates to another page or place, a button (<button>) performs an action such as submitting, opening or toggling. The element tells assistive technology what a control is and how it works, which WCAG 4.1.2 Name, Role, Value requires at Level A.

Button vs. link is one of the most common questions in front-end work, and the answer is short: a link takes you somewhere, a button does something. Both can be styled to look identical, but screen readers, keyboards and voice control treat them differently. When a "button" is really a link, or a link only runs JavaScript, people relying on assistive technology get the wrong role and the wrong keys.

What it means

WCAG 4.1.2 Name, Role, Value (Level A) requires that for all user interface components "the name and role can be programmatically determined". W3C notes that standard HTML controls meet this when they are used as specified – the role comes with the element. Pick the element by what happens on click:

Happens on click Element Screen reader says Keyboard
Opens another page, a file or a section via URL <a href="…"> "link" Enter
Submits, opens a dialog or menu, toggles, plays <button type="button"> "button" Enter and Space

Mixing them up has consequences. Screen reader users who browse a page's list of links will miss actions hidden as buttons, and expect a new page when they activate a "link" that opens a menu. W3C lists the related failures: F42 "when emulating links" and F59 "using script to make div or span a user interface control". Both are documented under 4.1.2, and F42 also under keyboard navigation (2.1.1).

Examples

Example
<!-- Navigates: a link -->
<a href="/pricing">See pricing</a>

<!-- Acts on the page: a button -->
<button type="button" aria-expanded="false" aria-controls="filters">
  Show filters
</button>

<!-- Wrong: a link that only runs script -->
<a href="#" onclick="openMenu()">Menu</a>

<!-- Wrong: a div pretending to be a button -->
<div class="btn" onclick="addToCart()">Add to cart</div>

The div has no role, cannot be reached with Tab and doesn't respond to Enter or Space. Rebuilding all of that with role="button", tabindex="0" and key handlers is possible, but a native <button> does it for free – that is the core idea of semantic HTML. Whichever element you use, it also needs a name: an icon-only button without text is an empty button.

Do

Use <a href> for navigation and <button> for actions, give every control a clear accessible name, style either one as you like, and keep type="button" on buttons outside forms that should not submit.

Don't

Use href="#" or javascript:void(0) links to run script, build clickable div or span elements, nest a button inside a link, or switch elements just to get a certain look.

    Questions

    When should I use a button instead of a link?

    Use a button whenever the click performs an action on the current page: submitting a form, opening a dialog, toggling a menu, playing a video, adding to a cart. Use a link whenever it takes the visitor to a new URL or a different place on the page.

    Can a link look like a button?

    Yes. WCAG doesn't care about the look, only about the element and its role. A "Get started" call to action that opens a sign-up page should stay a link, even if it is styled as a big button.

    Is role="button" on a link or div okay?

    It can work, but you then have to add focus, Enter and Space handling and every state yourself, as described in name, role, value. A native <button> is simpler and more robust.

    Why is href="#" bad?

    A link with href="#" pretends to navigate but only runs script. Screen readers announce it as a link, it jumps to the top of the page if the script fails, and it does not react to Space. Use a <button> for the action instead.

    Does the difference matter for voice control?

    Yes. People using voice control often say "click button" or "show links" to get numbered targets. If the element has the wrong role, the command doesn't find it.

    • Name, Role, Value: Controls Screen Readers Understand

      Name, Role, Value is WCAG success criterion 4.1.2: for every user interface component, the name and role can be programmatically determined, user-settable states, properties and values can be programmatically set, and changes are announced to assistive technologies. It is Level A.

      Read definition: Name, Role, Value: Controls Screen Readers Understand
    • Semantic HTML: Meaningful Markup for Accessibility

      Semantic HTML means marking up content with the elements that describe its meaning, such as h1–h6, nav, button or table. It lets assistive technology understand structure and relationships, as WCAG 1.3.1 requires.

      Read definition: Semantic HTML: Meaningful Markup for Accessibility
    • Empty Button: What the Error Means and How to Fix It

      An empty button is a button element with no accessible name – no text, no aria-label and no alt text on an image inside it. Screen readers announce only that it is a button, not what it does.

      Read definition: Empty Button: What the Error Means and How to Fix It
    • Keyboard Navigation: WCAG 2.1.1 Explained

      Keyboard navigation means that every function of a website can be reached and operated with a keyboard alone – usually with Tab, Shift+Tab, Enter, Space and the arrow keys. WCAG 2.1.1 requires it at Level A.

      Read definition: Keyboard Navigation: WCAG 2.1.1 Explained

    Let AI Handle Website Accessibility

    Built in Europe. Set up in 2 minutes, no developer needed. Put website accessibility on autopilot with AI-powered fixes and automated monitoring.

    1. 1Choose your plan
    2. 2Install in 2 min
    3. 3AI fixes your website
    4. Done