Skip to content

Accessible button patterns for shadcn

Rules / Actions: 11 rules and 4 guidelines

Buttons are the most common control in an app. shadcn’s Button gives you a handful of variants and sizes, and it is a real <button>, so it takes focus and responds to Enter and Space. The component cannot know which variant a button should have, what its label should say, where it belongs in a row, or what should happen when the form behind it is not ready. Those choices are made on every screen, and they come out differently each time. Nor can it know whether the thing it wraps with asChild should be a link or a button, since both look the same. The same goes for actions done by dragging, such as reordering a list with dnd-kit or dropping a file on an upload area.

Where buttons go wrong

  • Labels such as OK, Submit or Yes, which make people read the whole screen to learn what the button will do. ACT-001a
  • An icon-only button with no accessible name, or a name that describes the picture (“Trash”) instead of the action (“Delete invoice”). ACT-001b
  • Visible words and an accessible name that differ, so a person using voice control says what they see and nothing happens. ACT-001b
  • Three filled buttons in one card, so none of them stands out. ACT-002a, ACT-002b
  • Cancel and Save that swap places from one dialog to the next. ACT-003a
  • An Export button that sits somewhere new on every page. ACT-003b
  • A submit button that stays disabled until the form is valid, with nothing to say why. ACT-004, a guideline (our choice), and ACT-005
  • A clickable div that a keyboard never reaches and a screen reader never names, or a button that only changes the address, so opening it in a new tab does nothing. ACT-009, and ACT-009a, a guideline (our choice)
  • A Delete built as <a href="#">, announced as a link that goes nowhere. ACT-009b, a guideline (our choice)
  • Small icon buttons packed so tightly that a finger or an unsteady hand presses the wrong one. ACT-006
  • A list or a board that can only be rearranged by dragging, or whose only other way is the arrow keys. ACT-007a
  • A keyboard move that a screen reader reads out as “Picked up draggable item 3f9a”, or not at all. ACT-007b, a guideline (our choice)
  • A drop zone that looks the same whether or not a file is over it, or a column that stays highlighted after the card has moved on. ACT-008

How the rules fit together

A button’s label starts with a verb that names the action (ACT-001a), and its accessible name says what it does and contains the visible words (ACT-001b). Its style shows how much it matters: at most one most emphasised button in a group (ACT-002a), and at most one on a page, where an open dialog or sheet counts as a page of its own (ACT-002b). Its place is predictable: the confirming button last in a dialog’s row (ACT-003a), and a page’s buttons inside the part they act on, in the same spot on every page (ACT-003b). Its size leaves room to press it without hitting a neighbour (ACT-006). And its element matches what it does: everything people click to go somewhere or to act has a control role in code (ACT-009), a link when it only takes people somewhere (ACT-009a) and a button when it acts where they are (ACT-009b), whatever it looks like. The last two are guidelines (our choice).

Two texts deal with a submit button that is not ready. ACT-004 is a guideline (our choice): on a form longer than one screen, keep the submit button enabled, and let sending the form show what is missing. ACT-005 is a rule for every case where a submit button is unavailable: say in visible text, right before it, what the person still has to do.

Three texts cover dragging. ACT-007a says that anything people can drag can also be done with a single pointer and no drag, such as with buttons, a menu or a field. A keyboard route alone does not count, and neither does a swipe. ACT-008 marks on screen the place a dragged item would land, and only while it is over that place. ACT-007b, a guideline (our choice), tells assistive technology in words what each step of a keyboard move did. The keyboard route itself is KBD-001.

For buttons in confirmation dialogs, see the dialog patterns and destructive actions. For what a button shows while it waits for a reply, and how to stop a second press from sending twice, see loading states.

What WCAG requires and what the judges decide

Four rules here come from WCAG 2.2. Accessible names follow from 1.1.1 Non-text Content, 2.5.3 Label in Name and 4.1.2 Name, Role, Value, and the last of these also asks for a control role on everything people click. Target size comes from 2.5.8 Target Size (Minimum), and a way without dragging from 2.5.7 Dragging Movements.

Most of the rest are decided by the judges. A mark on the place where a dragged item will land had both judges who spoke. Labels that start with a verb, one emphasised button per group, the order of a dialog’s buttons and a page’s buttons in a steady place had all three judges in support. Text next to an unavailable submit button had both judges who spoke. One primary button per page is a majority, two of three. Whether a long form’s submit button should stay enabled split the two judges who spoke, so ACT-004 is a guideline: our choice, with our reasons on its page. No judge has spoken on announcing a keyboard move, so ACT-007b is a guideline too. Only one judge has spoken on choosing a link or a button by what the control does, so ACT-009a and ACT-009b are guidelines as well.

Rules and guidelines

Each one has its own page with the full rule, Do and Don't cases, exceptions and the verdict. A rule is decided by WCAG 2.2 or by the judges. A guideline is our own choice. How the method works

Required by WCAG 2.2

A WCAG 2.2 Level AA criterion requires the behaviour. Where a rule adds advice of its own, it says so.

Decided by the judges

No WCAG criterion requires these. The judges who spoke support them, all or most of them.

  • ACT-001a Start an action button with a verb that names the actionRule. Unanimous (3 of 3). Decided.Start the label of every button that performs, confirms or commits an action with a verb naming that action. Add the object unless the verb and its context say what it acts on; where the verb repeats or space is tight, it may go in the accessible name instead (ACT-001b). Never use OK, Yes, No, Submit or a noun alone.
  • ACT-002a Give at most one button in a group the most emphasised styleRule. Unanimous (3 of 3). Decided.Among the buttons shown together for one task or decision, such as the action row of a form, dialog, sheet or card, give at most one the most emphasised style, for the action most people want there, and give every other button a less emphasised style; a group may have no emphasised button at all.
  • ACT-002b Use at most one primary button on a pageRule. Majority (2 of 3). Decided.Give a page at most one button in the most emphasised style, default or destructive, for the main task of the page; a dialog, sheet or side panel counts as its own page while it is open, and the actions of other sections, cards and smaller tasks use less emphasised styles.
  • ACT-003a Put the confirming button last in a dialog's row of buttonsRule. Unanimous (3 of 3). Decided.When a dialog's action buttons sit side by side, put the confirming or primary button last, at the trailing end of the row (the right in left-to-right languages, the left in right-to-left), with Cancel or the other dismissive action before it and no action button after it.
  • ACT-003b Put a page's buttons in the part they act on and keep them in the same placeRule. Unanimous (3 of 3). Decided.On a page, put a button that acts on one part inside that part, and a button that acts on the whole page in the page's own header, action bar or floating button. Give the same task the same area and position on every page at a given window size.
  • ACT-005 Say next to an unavailable submit button what is still neededRule. Unanimous (2 of 2). Decided.When a button that submits or continues a form is unavailable because required input is missing, show visible text directly before the button in reading order that says what the person must still do to make it work, and make that text readable without focusing the button. A required value that is filled in but not valid counts as missing.
  • ACT-008 Mark where a dragged item would land, and only while it is over that placeRule. Unanimous (2 of 2). Proposed, may still change.While something is being dragged, mark on screen the place that would receive it if it were let go now. Remove the mark as soon as the dragged thing leaves that place, is dropped or the drag is cancelled.

Guidelines, our choice

The judges are split or too few have spoken, so we choose and give our reasons. A product that chooses otherwise is not wrong.

All rules · Is shadcn accessible? · Give the rules to an AI agent

Justified by Blackwood & Blake helps you work toward WCAG 2.2 AA. It is not a certification. Read more