Skip to content
Tutorials Center
My learning

Topics

Lesson 12 of 38 ยท Semantic HTML and ARIA

Links and Buttons

Learn when to use a link and when to use a button, how to write descriptive link text, how to name icon buttons, and why div and span click handlers fail.

Links and buttons are the most common interactive elements on the web, and they are easy to get wrong. A user needs to know two things about each one: what it is (a link goes somewhere, a button does something) and what it is called. Native <a> and <button> elements provide both, plus keyboard support, for free.

This lesson gives you the rule for choosing between them, shows how screen readers present each, teaches you to write link text that works out of context, and explains why fake buttons made of div elements are a classic accessibility failure.

The question to ask is: does it navigate, or does it act?

  • Link (<a href>): goes to another page, another place on this page or a resource such as a download. It can be opened in a new tab and shared by copying the address.
  • Button (<button>): performs an action on the current page, such as opening a dialog, submitting a form, toggling a menu or saving.

Screen readers announce "link" or "button", and users rely on that to predict what will happen. Pressing Enter activates both a link and a button, but Space activates only a button. A link without an href is not focusable and not a link at all.

Link or button?

Link Goes somewhere. Uses a, href
Button Does something. Uses button
Keys Enter for both, Space for buttons

If it changes the URL, use a link.

1 / 2

What you get for free

Native vs fake controls

tabIndex of the fake div is -1 (not focusable) while the button and link report 0. If a button is built from a div, you must add role="button", tabindex="0", key handlers for Enter and Space, a focus style and disabled handling. A real <button> does all of that already.

A link's text must make sense out of context, because screen reader users often pull up a list of all links on the page. Compare:

  • Weak: "Click here", "Read more", "More", "Link"
  • Better: "Read the accessibility policy", "Download the 2025 annual report (PDF, 2 MB)"

If design forces a short "Read more" label, add the context with visually hidden text or aria-label, but keep the visible words inside the name (WCAG 2.5.3 Label in Name), so voice control users who say the visible words can still activate it.

Link list audit

The first "Read more" is flagged. The second passes thanks to its hidden suffix, and the third is already descriptive.

Names for buttons

A button's name usually comes from its text. For icon-only buttons, add aria-label (see images and text alternatives). Name the action, "Close dialog" or "Add to cart", not the icon. When several identical buttons repeat, such as "Delete" in a table, add the context: "Delete invoice 1042".

If a link opens a new tab, say so in the text or with an icon that has a text alternative, so the user is not surprised (WCAG 3.2.5 advice). For downloads, mention the file type and size. Avoid target="_blank" as the default.

Disabled buttons

A disabled button leaves the tab order and is skipped, so users may never learn why they cannot continue. Prefer leaving the button enabled and showing a clear error on submit, or use aria-disabled="true" with an explanation tied by aria-describedby. Make sure aria-disabled buttons also ignore the click in script, because ARIA does not block it.

Common mistakes

  • <a href="#" onclick="doThing()">: a link pretending to be a button. Use <button>.
  • <button onclick="location.href='/x'">: a button pretending to be a link. Use <a>.
  • Removing the focus outline with outline: none and no replacement.
  • Wrapping a <button> inside an <a> or the reverse. Interactive content must not nest.
  • Using the same text for different destinations ("Details" ten times).

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. A control opens a dialog on the same page. Which element?

    It performs an action instead of navigating, so a button is correct and brings keyboard support.
  2. 2. Which key activates a native button but not a link?

    Links respond to Enter only, while buttons respond to both Enter and Space.
  3. 3. Which link text works best out of context?

    Descriptive text still makes sense in a screen reader's list of links.
  4. 4. Why is a div with a click handler a poor button?

    The native button includes role, focusability and keyboard behavior, and a div needs all of it recreated.

Summary

  • Links navigate and buttons act; choose the native element that matches.
  • Native a and button give role, focus and keyboard behavior automatically.
  • Link text must make sense out of context, and button names should describe the action.
  • Avoid fake controls, vague text and unexpected new tabs.

Next: ARIA Basics