
What Is This Button Called? Accessible Names, Tested on 42 Markup Patterns
Every button, link and input has an accessible name, the text a screen reader announces and a voice-control user says out loud. We read the names Chromium computes for 42 common markup patterns, from icon buttons to placeholders, to show where names come from, what aria-label really overrides, and the mistakes that leave controls nameless.
A sighted user sees a little ✕ in the corner of a dialog and knows what it does. A screen reader user hears whatever the browser decided that button is called. If the answer is nothing, they hear "button", and they have to guess.
That "what is it called" text is the element's accessible name. It is what screen readers announce, what voice-control users say ("click Close"), and what testing tools like Playwright's getByRole("button", { name: "Close" }) match against. Get it wrong and the page still looks fine, which is exactly why this bug ships so often.
The rules for computing a name are written down (the current accname 1.2 is a W3C Working Draft that refines the published Recommendation), but they have a lot of steps and a few surprises. So instead of paraphrasing the spec, we built 42 small test pages and asked Chromium what it computed for each one. This post walks through the results: where names come from, what overrides what, what counts as content and what does not, and how to test it.
Terms used in this post
- Accessibility tree: a second version of the page the browser builds for assistive technology. Each node has a role, a name, a state and sometimes a description.
- Role: what the element is: button, link, textbox, checkbox, heading.
- Accessible name: what the element is called. "Save", "Close dialog", "Email".
- Accessible description: extra help text, read after the name, usually after a short pause. Not the same thing as the name.
- Screen reader: software that reads the page aloud (or to a braille display), for example NVDA, JAWS, VoiceOver and TalkBack.
- ARIA: a set of HTML attributes (
aria-label,aria-labelledby,roleand others) that change what goes into the accessibility tree without changing what the page looks like. - accname: the W3C spec, Accessible Name and Description Computation, that defines the algorithm browsers use.
How we tested
Each test page had one element with id="t". A Node script loaded the page in Chromium 153 with Playwright 1.63, then used the Chrome DevTools Protocol to read that element's node from the accessibility tree: its role, its computed name, and which source the name came from.
// Excerpt from the test script (Playwright + Chrome DevTools Protocol).
await page.setContent(`<!doctype html><html lang="en"><body>${html}</body></html>`);
const { root } = await cdp.send("DOM.getDocument");
const { nodeId } = await cdp.send("DOM.querySelector", { nodeId: root.nodeId, selector: "#t" });
const { node } = await cdp.send("DOM.describeNode", { nodeId });
const { nodes } = await cdp.send("Accessibility.getPartialAXTree", {
backendNodeId: node.backendNodeId, fetchRelatives: false,
});
console.log(nodes[0].role.value, JSON.stringify(nodes[0].name.value));
This is what Chrome hands to screen readers. We did not test other browsers or listen to each pattern with a real screen reader, and screen readers sometimes add their own tweaks on top. But the same code runs in Chrome, Edge and every other Chromium-based browser, and the computed name is what a screen reader starts from.
Where a name comes from: the order
Short answer: The browser tries sources in a fixed order and stops at the first one that gives a non-empty result:
aria-labelledby, thenaria-label, then the native label (<label>,alt,<legend>,<caption>), then the element's own text content (for buttons, links and similar roles), thentitle, then (for inputs)placeholder.
The accname spec lists these as numbered steps. Simplified, it reads like this:
- If the element is hidden and nothing points to it, its name is empty.
aria-labelledby: if it points to at least one element that exists, join the text of those elements with spaces.aria-label: if it is not empty, use it.- The host language's own label: in HTML that means a
<label>, an image'salt, a fieldset's<legend>, a table's<caption>. - Content: for roles that take their name from their content (buttons, links, headings, table cells and others), use the text inside, including the names of child elements like images.
- Tooltip: the
titleattribute. The spec says it is used "only if nothing else, including subtree content, has provided results."
Inputs add one more fallback after title: in our tests, Chromium used placeholder when nothing else was there.
A ladder of name sources from top to bottom: aria-labelledby, aria-label, native label such as label, alt, legend or caption, text content, title, and placeholder. The browser stops at the first one that gives a name.
Here is that order as a small runnable function. It works on plain objects instead of real DOM elements and skips many cases a browser handles, but the priority is the same one Chromium followed in our tests:
Output:
"Save" from content <button>Save</button>
"" from nothing <button><svg/></button>
"Close" from aria-label <button aria-label="Close"><svg/></button>
"Close dialog" from aria-label <button aria-label="Close dialog">X</button>
"Invoice 42" from aria-labelledby <button aria-labelledby="title" aria-label="Delete">
"Save" from content <button aria-label=" ">Save</button>
"Close" from content <button><span aria-hidden="true">×</span> Close</button>
"Home" from content <a href="/"><img alt="Home"></a>
"Email" from label <label for="e">Email</label><input id="e" placeholder="you@x.com">
"Email" from placeholder <input placeholder="Email">
"Settings" from title <button title="Settings"><svg/></button>
Icon buttons: the most common nameless control
Short answer: A button that contains only an SVG icon has no name. Add
aria-label, or put real text in it and hide that text visually.
Our results for buttons:
| Markup | Role | Name Chromium computed | Source |
|---|---|---|---|
<button>Save</button> | button | "Save" | contents |
<button><svg>…</svg></button> | button | "" (none) | – |
<button aria-label="Close"><svg>…</svg></button> | button | "Close" | aria-label |
<button><svg>…</svg><span class="sr-only">Close</span></button> | button | "Close" | contents |
<button title="Settings"><svg>…</svg></button> | button | "Settings" | title |
<button><img alt="Delete"></button> | button | "Delete" | contents |
<input type="submit" value="Send"> | button | "Send" | value |
<input type="submit"> | button | "Submit" | (browser default) |
The icon-only button is the one that bites. To a screen reader user it is announced as just "button". Voice-control users have nothing to say to click it, and getByRole("button", { name: "Close" }) will not find it.
Three fixes work, in roughly this order of preference:
- Visible text, if the design allows it. The best name is one everybody can see.
- Visually hidden text (the
sr-onlypattern: a span that is clipped to 1×1 pixel). It counts as content, so the button gets its name from it, and it is ordinary text in the page like any other. aria-label="Close". Short and reliable.
title does produce a name in Chromium, but do not rely on it: it only shows as a tooltip on mouse hover, so keyboard and touch users never see it, and the spec treats it as the last resort.
aria-label overrides everything you can see
Short answer:
aria-labelreplaces the element's visible text as its name. If the visible text and thearia-labeldiffer, screen reader and voice-control users get a different label from everyone else.
| Markup | Name |
|---|---|
<button aria-label="Close dialog">X</button> | "Close dialog" |
<button aria-label="Purchase this item">Buy now</button> | "Purchase this item" |
<label for="e">Email</label><input id="e" aria-label="Work email"> | "Work email" |
<button aria-label="">Save</button> | "Save" |
<button aria-label=" ">Save</button> | "Save" |
The first one is fine: "X" is a poor name and "Close dialog" is better. The second one is a real bug. A voice-control user sees a button that says "Buy now", says "click Buy now", and nothing happens, because the button is called "Purchase this item". The third one does the same thing to a form field: the visible label says "Email", the name says "Work email".
This is WCAG 2.5.3 Label in Name, a Level A success criterion: for components with a visible text label, "the name contains the text that is presented visually." The W3C's explanation adds that "when a visible label already exists, aria-label should be avoided or used carefully". The safe pattern is to make the name start with the visible text: "Buy now, Pro plan" is fine; "Purchase this item" is not.
Note the last two rows: an empty or whitespace-only aria-label is ignored, and the browser moves on to the content.
A button that shows the text Buy now, while its accessible name is Purchase this item. A voice command saying click Buy now does not match the name, so nothing happens.
The check is simple enough to automate. This version normalises case and punctuation and checks that the visible text appears inside the name:
Output:
button "Save" ok
button "" FAIL no accessible name
button "" ok
button "Buy now" FAIL visible "Buy now" is not in the name "Purchase this item"
button "Buy now" ok
link "Read more" ok
textbox "E-mail" ok
aria-labelledby: the strongest source, with surprises
Short answer:
aria-labelledbypoints at other elements by ID and beats every other source, evenaria-label. It can point at hidden elements, at several elements, and even at the element itself.
| Markup | Name |
|---|---|
<span id="l">Delete invoice</span><button aria-label="Delete" aria-labelledby="l"> | "Delete invoice" |
<span id="l" hidden>Hidden name</span><button aria-labelledby="l"> | "Hidden name" |
<span id="a">Delete</span><span id="b">invoice 42</span><button aria-labelledby="a b"> | "Delete invoice 42" |
<h2 id="h">Invoice 42</h2><button id="t" aria-labelledby="t h">Delete</button> | "Delete Invoice 42" |
<button aria-labelledby="nope">Save</button> (no element with that ID) | "Save" |
Things worth knowing from these results:
- It wins over
aria-label. If both are present,aria-labelis ignored. - Hidden elements still count. Normally hidden content is left out of names, but the spec makes an exception: when you reference something directly, "an author can explicitly override that and include hidden text as part of the accessible name." Handy for reusing text that is not on screen.
- Several IDs are joined with spaces, in the order you list them. Pointing at the button itself plus the heading gives "Delete Invoice 42", a useful way to make ten identical "Delete" buttons distinguishable in a table.
- A broken reference is silently skipped. With no element matching
nope, Chromium fell back to the content. No error, no warning. If someone renames an ID, the label quietly disappears.
What counts as content
Short answer: Text inside the element counts, including visually hidden text, CSS
::beforeand::aftercontent, and child images'alt. Text that isaria-hidden="true",display: noneorvisibility: hiddendoes not.
| Markup | Name |
|---|---|
<button><span aria-hidden="true">×</span> Close</button> | "Close" (with a leading space) |
<button><span style="display:none">Secret</span>Close</button> | "Close" |
<button><span style="visibility:hidden">Secret</span>Close</button> | "Close" |
<button> with CSS #t::before { content: "★ " } and text "Favourite" | "★ Favourite" |
<a href="/"><img alt="Home"></a> | "Home" |
<a href="/home"><img src="logo.png"></a> (no alt) | "" (none) |
<a href="/p"><h3>Pricing</h3><p>Plans from $9</p></a> | "Pricing Plans from $9" |
Two of these catch people out.
CSS-generated content is part of the name. The decorative star became the first word of the button's name. If you use ::before for icons (icon fonts often do), the icon's character can end up being read out. Use aria-hidden on a real element for decorative icons instead of generated content, or make sure the generated content is empty for assistive technology.
A linked image without alt gives the link no name. The logo-in-a-link pattern is everywhere. Without alt, Chromium had nothing to use, so the link is announced with no name at all.
The last row shows the opposite problem: a "card" link that wraps a heading and a paragraph gets all of that text as its name. That is a mouthful when tabbing through ten cards, and it is one reason people put the link on the heading only.
Content that counts toward a name: visible text, visually hidden text, CSS generated content and image alt text. Content that does not count: aria-hidden text and display none text.
Form fields: labels, placeholders and titles
Short answer: Use a
<label>. A placeholder ortitledoes produce a name in Chromium when nothing else exists, but a placeholder disappears as soon as the user types, and both are last-resort fallbacks.
| Markup | Name | Source |
|---|---|---|
<label for="e">Email</label><input id="e"> | "Email" | label (for) |
<label>Email <input></label> | "Email" | label (wrapping) |
<label for="e">Email</label><input id="e" placeholder="you@example.com"> | "Email" | label (placeholder ignored) |
<input placeholder="Email"> | "Email" | placeholder |
<input title="Email address"> | "Email address" | title |
<input title="Email address" placeholder="you@example.com"> | "Email address" | title beats placeholder |
<label for="e">Email</label><label for="e">(required)</label><input id="e"> | "Email (required)" | both labels |
<label>Repeat every <select>…</select> days <input type="checkbox"></label> | "" (none) for the checkbox | – |
<label for="c">Repeat every <select>…3…</select> days</label><input id="c" type="checkbox"> | "Repeat every 3 days" | label, with the select value |
A placeholder-only input looks labelled and has a name, so automated checks often pass it. The problem is for people: the placeholder vanishes the moment they start typing, so anyone who loses their place (or uses a screen magnifier, or has a short memory) is left with an unlabelled field. The WCAG explanation quotes the HTML spec on this: "The placeholder attribute should not be used as an alternative to a label."
The two rows near the bottom are worth a second look:
- A
<label>labels only one control. When a label wraps a<select>and a checkbox, the label belongs to the first labelable element inside it (the select). The checkbox gets no name at all. - Labels can include a control's value. When the label points at the checkbox with
forand contains a select, the select's current value is included: "Repeat every 3 days". This is step 2C in the spec, "embedded control", and it means the name changes when the user picks a different value.
A label element wrapping a select and a checkbox. The label is attached to the select, the first control inside it, so the checkbox ends up with no name.
Things that are not names
Short answer:
aria-describedbyandtitle(when there is other text) produce a description, not a name. Andaria-labelon a plain<div>or<span>is not allowed by the ARIA spec, even though Chromium still records it.
| Markup | Name | Description |
|---|---|---|
<button aria-describedby="d"><svg>…</svg></button><p id="d">Removes the item</p> | "" | "Removes the item" |
<button title="Saves a draft">Save</button> | "Save" | "Saves a draft" |
<div aria-label="Main area">Content</div> | "Main area" (role: generic) | – |
<span role="button" tabindex="0" aria-label="Play"></span> | "Play" | – |
aria-describedby does not rescue an icon button. The button still has no name; the help text is read as extra information after it.
The <div aria-label> row is a trap. Chromium put the label in the tree (Playwright, as we found later, did not), but WAI-ARIA 1.2 lists generic (the role of a plain div or span) among the "roles which cannot be named", along with paragraph, presentation, code, strong and a few others, and accname says authors "MUST NOT use the aria-label or aria-labelledby attributes to name the element" for those roles. Screen readers are free to ignore it, so do not count on it. Give the element a real role (role="region", a <section> with a heading, a <nav>) or use visible text instead. The <span role="button"> row shows that once the role allows a name, aria-label works fine (it still needs keyboard handling, which is why a real <button> is better).
Groups and tables have native labels too: a <fieldset> was named by its <legend> ("Shipping"), and a <table> by its <caption> ("Q3 sales").
Testing accessible names
Because names are invisible, they are perfect for automated tests. Two Playwright features read them directly:
getByRole(role, { name })finds an element by role and accessible name. If an icon button loses its label, the test fails, so every test written this way doubles as a small accessibility check.locator.ariaSnapshot()prints the accessibility tree of a part of the page as YAML-like text, which you can compare against a stored snapshot.
Here is what ariaSnapshot() printed (Playwright 1.63) for a small form with a placeholder-only search box, an icon button with no label, a labelled email field, a labelled close button and a link:
- textbox "Search products"
- button:
- img
- text: Email
- textbox "Email"
- button "Close":
- img
- link "Read more":
- /url: /a
The unnamed button stands out immediately: button: with no name in quotes. One more thing from that run: getByLabel("Search products") found 0 elements, because getByLabel looks for real labels and aria-label, not placeholders (Playwright has a separate getByPlaceholder). getByRole("textbox", { name: "Email" }) found 1. Note that Playwright computes names with its own implementation of the same spec. We ran all 42 test cases through ariaSnapshot() and it agreed with Chromium on 41. The exception was <div aria-label="Main area">: Playwright gave it no name, which is what the ARIA spec says should happen (more on that above).
For broader coverage, run an automated checker such as axe-core in your test suite. It flags nameless buttons, links and inputs. It cannot judge whether a name makes sense, so the "Label in Name" check above and a quick listen with a real screen reader are still worth doing.
Common mistakes
- Icon-only buttons and links with no text or
aria-label. The single most common case. They are announced as just "button" or "link". aria-labelthat does not match the visible text. Voice-control users cannot click it by name, and it fails WCAG 2.5.3.- Placeholder instead of a label. It has a name, but sighted users lose it as soon as they type.
- Linked images without
alt. The link has no name. aria-describedbyas a substitute for a name. It adds a description; the name is still empty.aria-labelon adivorspanwith no role. Not allowed by the spec, and not reliable.- Ten "Read more" or "Delete" links with identical names. Out of context (screen reader users often list all links on a page) they are indistinguishable. Use
aria-labelledbyto add context, or visually hidden text. - Renaming an ID used by
aria-labelledby. The browser silently falls back to other sources or to nothing.
How to answer this in an interview
A common prompt is "This icon button is not accessible. How would you fix it?" or "What is the difference between aria-label, aria-labelledby and aria-describedby?" A strong answer:
- Define the accessible name: the text assistive technology uses to identify a control, computed by the browser from a fixed list of sources.
- Give the order:
aria-labelledby,aria-label, native label (<label>,alt,<legend>), content, thentitleandplaceholderas last resorts. - Fix the icon button with visible text, visually hidden text, or
aria-label, and say whytitleis not enough (mouse hover only). - Mention Label in Name: an
aria-labelmust contain the visible text, or voice-control users cannot activate the control. - Separate name from description:
aria-describedbyadds extra information read after the name; it does not name anything.
Follow-ups to expect: "Can aria-labelledby point at a hidden element?" (yes, and the hidden text is used). "Why prefer native HTML over ARIA?" (a <button> with text needs no ARIA at all, and gets keyboard support built in). "How would you test it?" (getByRole with a name, an accessibility tree snapshot, axe-core in CI, and a real screen reader for anything important).
Cheat sheet
| Question | Answer |
|---|---|
| What is an accessible name? | The text a screen reader announces and voice control matches for an element. |
| Which source wins? | aria-labelledby > aria-label > native label > content > title > placeholder. |
| Icon-only button? | No name. Add visible text, sr-only text or aria-label. |
Does aria-label override visible text? | Yes, completely. Keep the visible text inside it (WCAG 2.5.3). |
Empty aria-label=""? | Ignored; the browser moves on to the next source. |
aria-labelledby to a hidden element? | Works; the hidden text is used. |
Broken aria-labelledby ID? | Silently skipped. |
Does aria-hidden text count? | No. Neither does display: none or visibility: hidden text. |
Does CSS ::before content count? | Yes, it becomes part of the name. |
| Placeholder as a label? | Gives a name, but disappears when typing. Use a <label>. |
aria-describedby? | A description, not a name. |
aria-label on a plain div? | Prohibited by the ARIA spec for the generic role. Do not rely on it. |
| How to test? | getByRole(role, { name }), ariaSnapshot(), axe-core, and a real screen reader. |
Enjoyed this read?
More from Arvind Nishad
- Retries Without a Retry Storm: Backoff, Jitter and Retry Budgets, Measured
- React Interview Follow-Up Questions, With Every Answer Run in React 19
- Temperature, Top-k, Top-p and Min-p: What LLM Sampling Settings Actually Do
- Postgres Composite Indexes: Column Order, Covering Indexes and Skip Scan, Measured on 5 Million Rows
Related stories

React Compiler in Practice: What It Memoizes, What It Skips, and When You Still Need useMemo
We ran React Compiler 1.0 on real components and counted renders. Here is what the compiled code looks like, which components it silently skips, the one bug it can introduce, and where useMemo still earns its place.
How the event loop really schedules your code
How the event loop really schedules your code — lessons learned the hard way, distilled into something you can use today.
From REST to typed APIs: what changed for our team
From REST to typed APIs: what changed for our team — lessons learned the hard way, distilled into something you can use today.
Responses (0)
Sign in to join the discussion.