Name, description and state answer different questions
A classroom cupboard may have a name, an instruction and a note saying whether it is open. An interface has similar needs. An accessible name identifies a control, such as Practice topic. A description adds information, such as which kind of answer to enter. A state reports a current condition, such as expanded or collapsed.
Assistive tools use this information to explain the interface. Do not put every instruction into one long name or assume a visual arrow tells everyone whether a panel is open.
Start with the native name
Visible text inside a button normally names it. A label connected with for and id names a form field. A link generally gets its name from its content, including an image alternative when appropriate. These native connections should be the first choice.
A class such as blue-button does not supply a useful name. Placeholder and title should not replace a persistent visible label. Keep the name specific enough to distinguish neighbouring actions, while avoiding unnecessary wording such as button in the visible text.
Aria-labelledby reuses existing text
Aria-labelledby points to one or more ids whose text supplies the name. The first example uses a visible h2 to name its section. Reusing that heading keeps the visible wording and the reported name together.
HTML fragment — part of a document
<sectionaria-labelledby="topic-heading"><h2id="topic-heading">Choose a practice topic</h2><p>Use this section for a short topic question.</p></section>
The id belongs to the heading. The reference contains the id without a hash. Keep ids unique and spelling exact. When several ids are listed, their referenced text is combined in the specified order.
Aria-label supplies a text name directly
Aria-label can name an element when no suitable visible naming text is available. For example, it can distinguish two navigation areas. It can override the element's usual name, so do not add it automatically to every button or link.
If a visible button says Save notes but its aria-label says Delete account, different readers receive conflicting instructions. Keep visible words and the accessible name aligned. A meaningful visible label is generally easier for everyone to find and maintain.
Aria-describedby connects extra information
Aria-describedby points to explanatory text. In the topic example it associates the field with the visible topic instruction, while the ordinary label continues to name the field. It is not a replacement for that label.
A description can explain a format, limit or relevant context. Put useful information in persistent visible wording. Tool behaviour can vary, so test actual combinations rather than claiming a particular sentence is always spoken in one exact order.
Aria-expanded describes the actual open state
Aria-expanded=false on our button reports a collapsed controlled panel. When it opens, the value becomes true. Aria-controls identifies the panel by id; it does not create the show/hide action. These ARIA values are text tokens: false has meaning here, unlike a boolean HTML attribute such as open.
The script must change both the reported state and panel visibility. The example uses hidden for the closed panel. For a straightforward optional note, the native details/summary control from Chapter 41 often avoids writing this extra code.
Read the small state-changing script
The script finds the button and panel. GetAttribute reads the current state text. The comparison with "true" creates a true-or-false value. The exclamation mark in !expanded reverses that value; String turns the result into the text used for the attribute.
Setting hint.hidden to the old expanded value closes a previously open panel and reveals a previously closed one. Native button activation supplies the normal keyboard route; we have not recreated it with a clickable div. The tutorial preview disables the script, so test this behaviour in the saved file.
Use roles and hidden content carefully
A role tells assistive tools what kind of interface element something represents. It does not add the missing events or keyboard logic. Do not add role=button to a div when a native button already fits. Aria-hidden=true hides content from the accessibility tree but does not visually hide it or prevent keyboard focus.
Do not apply aria-hidden to an active control. For ordinary hidden content, use the appropriate native visibility mechanism and maintain focus sensibly. A short example can demonstrate a state connection; it does not prove full accessibility across assistive technology.
Follow the idea
Three useful questions
1Name: what is this control?
2Description: what else should I know?
3State: what is true right now?
4Behaviour: does the action match that state?
ARIA describes an interface; it does not implement missing interaction.
Complete program: named-practice.html
Save this as named-practice.html. Open it in your browser.
named-practice.html
<!doctype html><htmllang="en"><head><metacharset="UTF-8" /><metaname="viewport"content="width=device-width, initial-scale=1" /><title>Names and Descriptions for Practice</title></head><body><h1>Give each control a clear purpose</h1><main><sectionaria-labelledby="topic-heading"><h2id="topic-heading">Choose a practice topic</h2><p><labelfor="topic-answer">Practice topic</label></p><pid="topic-instruction">
Enter a short topic such as headings. This field is not submitted anywhere.
</p><inputtype="text"id="topic-answer"name="topic"aria-describedby="topic-instruction" /></section><navaria-label="Related practice"><ahref="aria-disclosure.html">Try the expandable hint example</a></nav></main></body></html>
Browser previewDocument title: Names and Descriptions for Practice
This preview shows the example in a browser. Save the complete code in local files to test links between pages and downloads. Same-page section links work here.
Expected result: a visibly labelled field with a separate instruction and a named topic section. The field is editable but is not submitted. The related link opens the second example when both files are saved together.
Complete program: aria-disclosure.html
Save this as aria-disclosure.html. Open it in your browser.
aria-disclosure.html
<!doctype html><htmllang="en"><head><metacharset="UTF-8" /><metaname="viewport"content="width=device-width, initial-scale=1" /><title>Synchronise a Disclosure State</title></head><body><h1>Explain a custom expandable hint</h1><main><p>
Save this page to run its small script. For ordinary expandable notes, details and summary
are often simpler.
</p><buttontype="button"id="hint-button"aria-expanded="false"aria-controls="hint-content">
Practice hint
</button><divid="hint-content"hidden><p>Read a relative path from the folder containing the current HTML file.</p></div><script>
const button = document.getElementById('hint-button');
const hint = document.getElementById('hint-content');
button.addEventListener('click', function () {
const expanded = button.getAttribute('aria-expanded') === 'true';
button.setAttribute('aria-expanded', String(!expanded));
hint.hidden = expanded;
});
</script></main></body></html>
Browser previewDocument title: Synchronise a Disclosure State
This preview shows the example in a browser. Save the complete code in local files to test links between pages and downloads. Same-page section links work here. JavaScript does not run in this preview. Save the complete example and any named script file together to test its actions or canvas drawing in your browser.
Expected result in the saved page: the hint begins hidden and aria-expanded begins false. Mouse or keyboard activation reveals it and changes the state to true. Another activation reverses both. The isolated tutorial preview keeps the initial state and explains that scripts do not run.
Problem and solution
Problem: a panel appears after activation, but the button still reports aria-expanded=false.
Solution: update visibility and the reported state together in the same action. Then test opening and closing with both mouse and keyboard.
Common mistakes and useful tips
Use native naming before adding ARIA.
Do not use conflicting visible and accessible names.
Referenced ids must exist and be unique.
Aria-controls does not implement behaviour.
Keep aria-expanded consistent with the panel.
Aria-hidden does not remove a control from keyboard access.
Practice questions
What does an accessible name identify?
Which attribute reuses a visible heading as a name?
What does aria-describedby add?
Does aria-controls open a panel?
What state should a visible open hint report?
Save the disclosure example. Activate it twice with the keyboard and compare the panel with the attribute.
Check your practice answers
The element or control, such as Practice topic.
Aria-labelledby.
Extra explanatory information, separate from the name.
No. It identifies the controlled element; behaviour must be implemented.
Aria-expanded=true on its controlling button.
The first activation reveals the panel and reports true. The second hides it and reports false. The button remains usable.
Interview questions
How do name and description differ?
The name identifies the element; the description explains extra information. A field can need both without combining them into one long label.
Why prefer aria-labelledby when a suitable heading exists?
It can reuse the visible wording, keeping the label people see and the name tools receive consistent.
Does adding role=button make a div a complete button?
No. It supplies semantics but not all native interaction. Use a real button when it fits.
Why test both states of a disclosure?
A one-way visual change can leave the reported state, focus or closing action incorrect. Both directions need to stay consistent.