Agent Wranglers

Accessibility Required

Announce changes without moving focus

Announce changes such as "Copied" or "3 results" through a live region that is already in the page, without moving focus. This is WCAG criterion 4.1.3 (AA).

How to do it

Put an empty <p role="status"> in the first HTML. Write the message into it when something happens. Use role="alert" only for urgent errors. See also use toasts only to confirm finished work.

Example

<button type="button" id="copy">Copy</button>
<p role="status" id="status"></p>
<script>
  document.getElementById('copy').addEventListener('click', async () => {
    await navigator.clipboard.writeText('hello@example.com');
    document.getElementById('status').textContent = 'Copied';
  });
</script>

How to check

A browser test triggers each action. The live region was in the initial HTML, now holds the message, and document.activeElement did not change.

For agents: if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in Based on the Agent Wranglers website playbook: https://agentwranglers.se/playbook/website/accessibility/status-messages.