Conceptual Question

aria-label, aria-labelledby, and aria-live in practice

Accessibility

aria-label, aria-labelledby, and aria-live in practice

A file picker has an icon-only control to remove a file, a visible heading above its upload list, and a message that changes to “Upload complete.” What does each element need so a screen-reader user can understand and use it?

Interview answer

Use native elements and visible labels first. aria-label supplies an accessible name when a control has no suitable text, while aria-labelledby uses text from an element that already exists on the page. aria-live controls how assistive technology announces changes to a region. For a routine status update, role="status" provides a polite live region.

Name the control and the region

HTML
<section aria-labelledby="upload-title">
<h2 id="upload-title">Uploaded files</h2>
<ul>
<li>
<span>receipt.pdf</span>
<button type="button" aria-label="Remove receipt.pdf">
<span aria-hidden="true">×</span>
</button>
</li>
</ul>
<p id="upload-status" role="status"></p>
</section>

The section gets the name Uploaded files from its visible heading. The button gets the name Remove receipt.pdf, so the user can distinguish it from remove buttons on other rows. The decorative × is hidden from assistive technology. A text button can use its own text, and a form input can use a native label with a matching for attribute. If a control already has visible text, include that text in its accessible name so voice-control users can refer to what they see.

aria-labelledby uses element IDs and takes precedence over aria-label when valid. Use aria-describedby for extra context such as a file-size limit. Keep the field’s name short and let the description supply those details.

Announce a change while keeping focus in place

Render the empty status region when the UI mounts. When the upload finishes, update the text of that same element to something like “receipt.pdf uploaded.” Its polite status can be announced without shifting focus from the current control. Keep the status message visible if it helps sighted users too. A live region works best for meaningful, concise changes. Announcing every progress tick or placing aria-live on the whole upload list can interrupt other information.

For an urgent interruption, an alert can be appropriate. If removing a file also removes the focused button, move focus deliberately to a nearby remove button or back to the file picker. The live announcement and keyboard focus solve different problems.

Interview follow-up

How would you verify the result? Inspect the button’s computed accessible name. Tab to the control and confirm it has a visible focus indicator and can be activated with the keyboard. Start with the status region already mounted, complete an upload, and check with a real browser and screen reader that the update is announced and focus stays where you intend.

Further reading · W3C accessible names and descriptions · W3C status message technique