Skip to content

ACT-009b Build a control that acts where the person is as a button, also when it looks like a link

Level
Guideline, our choice
Verdict
Insufficient evidence (1 of 3 judges spoke)
Status
proposed, version 1.0.0

Rule

A control that acts where the person is, such as saving, deleting, switching something or opening a dialog or menu, is a button in code, also when it is styled as a link. Do not build it as an <a> with href="#" or javascript:void(0), or as a link whose click is cancelled by script.

Examples

Live examples built with Justified's components. Try them with the mouse, the keyboard or a screen reader.

Do: Acting in place is a button that looks like a link

Episode 42: Sleeping in the cold

38 minutes

On the episode row, Mark as played, Show episode notes and Share episode are Button variant="link", so they render <button>. They look like text links, are announced as buttons, and take Enter and Space. The list shows the state each carries: the notes say expanded or collapsed, and the share button says it opens a dialog. Focus goes into the dialog and back to the button.

Don't: Links to # whose click is cancelled

Episode 42: Sleeping in the cold

38 minutes

The same two actions as <a href="#"> with preventDefault. A screen reader says “link” and promises a new place, and both are in the list of links though they go nowhere. Tab and Enter work; press Space and the link does nothing; on a long page it scrolls instead. A middle click or Copy link address gives a useless #.

Do: A jump on the same page is a link

Episode 42: Sleeping in the cold

38 minutes

Jump to transcript
We start at the hut door. The snow is knee deep and the stove is already lit.

Jump to transcript has a real target, href="#…", so it is a link and moves focus to the transcript inside this scene. Print transcript acts, so it is a button. The list holds one of each.

Don't: href="#" when the script does not cancel

Episode 42: Sleeping in the cold

38 minutes

Without preventDefault the click follows #: the page jumps to the top and the address ends in #. Storybook cancels the jump for real, so the address line draws what would happen. Marking an episode as played changes nothing about the address, so it should have been a button.

Why

A screen reader says "link" for an <a href="#">, so people expect to leave the page, and the control turns up in the list of links though it goes nowhere. A button says what it is, takes Enter and Space, and can carry the states a menu, a toggle or a disclosure needs. WCAG 2.2, 4.1.2 Name, Role, Value asks that a control's role can be read, and its Understanding text says an element given a job other than its usual one needs extra care. 2.1.1 Keyboard is met by the anchor's Enter alone; it supports this guideline only in that a button also takes Space, the key people expect, which is our advice. Neither names a failure for a link that acts, so this is a guideline. An <a> with no href at all is ACT-009, a requirement.

Our reasons

Fewer than two judges have spoken about links that act, so the verdict is Insufficient evidence (1 of 3 judges spoke) and this guideline is our choice. Carbon supports it, and so does NN/g, an expert witness who does not vote. We choose a button for four reasons.

  • The role sets the expectation. "Link" promises a new place. A dialog that opens instead surprises the person who heard it.
  • A fake link breaks what links do. href="#" puts # in the address and jumps to the top of the page if the script fails or preventDefault is missing. A middle click opens a useless tab, and Copy link copies nothing worth having.
  • A button carries the state. aria-expanded, aria-pressed, aria-haspopup and aria-disabled belong on buttons; that each state is set and kept in step is VIS-008a. Radix and shadcn triggers render a <button> and set them for you, and wrapping an <a> in them with asChild throws that away.
  • The look stays free. Button variant="link" looks like a link and is a <button>.

Do

  • In a podcast app, each episode row has Mark as played styled as a text link: <Button variant="link" onClick={markPlayed}>Mark as played</Button>. It renders a <button>. The adapter's Button sets type="button" by default, so it never submits a form around it.
  • Show episode notes opens the notes below the row with CollapsibleTrigger, which renders a button and sets aria-expanded.
  • Share episode opens a dialog: <DialogTrigger asChild><Button variant="link">Share episode</Button></DialogTrigger>. Focus goes into the dialog and back to the button, as DLG-006 says.
  • Load more episodes at the end of the list is a button. Page numbers with an address each are links, as ACT-009a says.
  • Copy feed address, Print transcript and Remove from queue are buttons.
  • Our own advice: a button inside running text may look like the links around it, but people may then expect it to go somewhere, so name the action plainly, as ACT-001a asks.
  • The label of each button follows ACT-001a and its name ACT-001b.

Don't

  • Write <a href="#" onClick={(e) => { e.preventDefault(); setShareOpen(true) }}>Share episode</a>.
  • Use Next.js <Link href="#" onClick={markPlayed}> for Mark as played.
  • Give Remove from queue href="javascript:void(0)".
  • Put <a href="#"> inside DropdownMenuTrigger asChild for the menu Episode options.
  • Keep the anchor and add role="button" and a Space handler. That can meet 4.1.2, but it is the hand-built way ACT-009 calls worse; use a <button>.

Exceptions

  • A real link that also does something. A link with a real address that records the click, prefetches its page, or opens another program, such as a tel: address, still goes somewhere. Leave it a link.
  • A jump on the same page. href="#transcript" that moves to a part of the page is a link, not the href="#" this guideline is about.
  • Form controls. Switching something with a checkbox, a switch or a select keeps that control's own role; FRM-012b covers them.
  • Menus and tabs. Items inside a menu keep the menu item role, and Radix Tabs keep the tab role. Tabs that are routes are ACT-009a.
  • No href at all. An <a> with only a click handler has no role, which ACT-009 requires to fix.
  • A product that chooses otherwise. This is a guideline. A product that keeps such a link still gives it a name and keyboard use (ACT-001b, KBD-001).

Verdict

Insufficient evidence (1 of 3 judges spoke). Only the judges decide; the expert witnesses are shown but do not vote. The judges do not settle this one, so it is a guideline: our own choice, with our reasons above. How verdicts work

Stances on ACT-009b
SourceRoleStancePage
WCAG 2.2LawSupports4.1.2 Name, Role, Value
WCAG 2.2LawSupports2.1.1 Keyboard
Material DesignJudge No position
Apple Human Interface GuidelinesJudge No position
Carbon Design SystemJudge SupportsLink: usage
Button: accessibility
GOV.UK Design SystemExpert witness No position
Nielsen Norman GroupExpert witness SupportsButtons vs. Links: What's the Difference and Why Does it Matter? (Video), by Huei-Hsin Wang

Each stance links to the page it rests on, read on the date in the source register. This page never repeats what a source says; read the source itself.

History

  • Version 1.0.0, : First version.

Last checked against the other rules for conflicts on .

More in Actions: 11 rules and 4 guidelines · All rules