Live Regions for Dynamic Updates
Uses ARIA live regions to announce dynamic content changes to screen readers, supporting polite and assertive announcement modes.
Code
<!-- Polite: announces when screen reader is idle -->
<div id="status" role="status" aria-live="polite">
Ready
</div>
<!-- Assertive: interrupts current announcement -->
<div id="alert" role="alert" aria-live="assertive">
</div>
<!-- Log region for sequential messages -->
<div id="log" role="log" aria-live="polite" aria-relevant="additions">
</div>
<!-- Timer updates -->
<div id="timer" role="timer" aria-live="off" aria-atomic="true">
00:00
</div>
<button onclick="showStatus('Processing...')">Start</button>
<button onclick="showAlert('Error: Invalid input')">Trigger Error</button>
<button onclick="addLog('New message')">Add Log</button>
<script>
function showStatus(message) {
document.getElementById('status').textContent = message;
setTimeout(() => {
document.getElementById('status').textContent = 'Complete';
}, 2000);
}
function showAlert(message) {
const alert = document.getElementById('alert');
alert.textContent = '';
setTimeout(() => {
alert.textContent = message;
}, 100);
}
function addLog(message) {
const log = document.getElementById('log');
const entry = document.createElement('div');
entry.textContent = `[${new Date().toLocaleTimeString()}] ${message}`;
log.appendChild(entry);
}
let seconds = 0;
const timer = document.getElementById('timer');
setInterval(() => {
seconds++;
const m = String(Math.floor(seconds / 60)).padStart(2, '0');
const s = String(seconds % 60).padStart(2, '0');
timer.textContent = `${m}:${s}`;
}, 1000);
</script>ARIA live regions announce dynamic changes: aria-live="polite" waits for idle, assertive interrupts immediately. role="status" (polite) and role="alert" (assertive) are shortcuts. role="log" with aria-relevant="additions" announces new entries. aria-atomic="true" announces the entire region. Clearing then setting content ensures re-announcement. Use sparingly to avoid overwhelming users.
Interactive Tools for This Topic
WCAG Color Contrast CheckerCalculate WCAG 2.1 color contrast ratios between foreground and background colors. Verify AA and AAA compliance levels for normal and large text accessibility.JSON to Zod Schema ConverterInfer typed Zod z.object schemas from JSON payloads locally, supporting nested objects, merged array shapes, enums, nullable fields, and JSDoc comments.JSON Schema ValidatorValidate JSON data against a JSON Schema definition and get detailed error reports. Supports type checking, required fields, and common constraint validation.JSONL / NDJSON InspectorValidate NDJSON and JSON Lines line-by-line, pinpoint syntax errors by line number, analyze key frequencies and types, and export a pretty JSON array.
Report a problem with this exampleOpens a pre-filled issue on GitHub.