Screen readers read the page where the user is. When something changes elsewhere, such as a list that filters or a row that disappears, screen reader users don't hear about it unless the page tells them. IzzyBlazor tells them two ways:
LiveRegionholds hidden text that describes the page's state, such as "4 people". Screen readers read it each time the text changes.Announcertells screen reader users about something that just happened, such as "Revoked the invite". Call it from a form post or a C# handler.
Components announce their own changes: toasts, a CopyButton's "Copied", moves in a reorderable list. Use LiveRegion and Announcer for changes your own code makes.
Reading a count
Put a LiveRegion next to the content it describes, and set its Text from the same data. This list reads the number of people after each search:
Static
Preview
- Amara Okafor Design
- Ben Hartley Engineering
- Chen Wei Engineering
- Dana Fischer Sales
- Elif Demir Support
- Farid Haddad Engineering
- Grace Lindqvist Design
- Hugo Moreau Finance
Code
@* The page reads the search from the URL and filters its own list. Screen readers hear the count after each search. *@
<Stack Gap="4" MaxWidth="34.Rem" Grow>
<FilterForm Label="Filter people">
<FilterSearch Placeholder="Search by name or team" />
</FilterForm>
<LiveRegion Text="(Matches.Count == 1 ? "1 person" : $"{Matches.Count} people")" />
<List Plain Gap="3">
foreach (var person in Matches)
{
<ListItem>
<Row Gap="3" Align="Align.Center">
<Avatar Name="person.Name" Decorative Size="AvatarSize.Sm" />
<TextBlock As="span" Grow>person.Name</TextBlock>
<TextBlock As="span" Size="TextSize.Sm" Color="Color.Muted">person.Team</TextBlock>
</Row>
</ListItem>
}
</List>
</Stack>
{
[SupplyParameterFromQuery(Name = "q")] private string? Search { get; set; }
private List<Person> Matches => All
.Where(p => string.IsNullOrWhiteSpace(Search)
|| p.Name.Contains(Search, StringComparison.OrdinalIgnoreCase)
|| p.Team.Contains(Search, StringComparison.OrdinalIgnoreCase))
.ToList();
}Static: Each search updates the page without a full reload, and the new count is read.
Add this example to a page with the izzy CLI:
izzy add component LiveRegion --at <file>:<line>Screen readers only notice changes in a region that was already on the page, so put the LiveRegion on the page from the start, not inside an @if. Its first text isn't read. Setting the same text again isn't read either, since nothing changed.
For a status that shows on the page, such as a visible "4 of 8 people", put role="status" on the element that shows it rather than repeating it in a LiveRegion.
Announcing an action
To tell screen reader users what just happened, call Announce on the injected Announcer. Revoking an invite marks its row and turns the button into Undo. The button keeps focus, but screen readers don't read a focused button's new name, so the announcement says what happened:
Static
Preview
Pending invites
Code
Announcer Announcer
@* Once per app, in the layout: <AnnouncerRegion />, or a <ToastRegion />, which has one (the docs layout does). *@
<Card Title="Pending invites" MaxWidth="34.Rem" Grow>
<CardBody Flush>
<form method="post" @formname="invites" @onsubmit="Toggle" data-enhance>
<AntiforgeryToken />
@* Static pages: the invites already revoked post with the form. *@
foreach (var email in _revoked)
{
<input type="hidden" name="revoked" value="email" />
}
foreach (var email in Invites)
{
var revoked = _revoked.Contains(email);
@* Keyed, so the pressed button stays the same element and keeps focus as it turns into Undo. *@
<Row @key="email" Gap="3" Align="Align.Center" PaddingX="4" PaddingY="3" BorderTop="1">
<TextBlock As="span" Grow Truncate>email</TextBlock>
if (revoked)
{
<Badge Size="BadgeSize.Sm">Revoked</Badge>
}
<Button Submit Name="toggle" Value="email" OnClick="() => _clicked = email"
aria-label="($"{(revoked ? "Undo" : "Revoke")} {email}")"
Size="ControlSize.Sm" Variant="ButtonVariant.Ghost" Accent="(revoked ? Accent.Neutral : Accent.Danger)">(revoked ? "Undo" : "Revoke")</Button>
</Row>
}
</form>
</CardBody>
</Card>
{
[SupplyParameterFromForm(FormName = "invites", Name = "toggle")] private string? Posted { get; set; }
[SupplyParameterFromForm(FormName = "invites", Name = "revoked")] private string[]? PostedRevoked { get; set; }
// Interactive pages post nothing, so OnClick says which button it was.
private string? _clicked;
private HashSet<string> _revoked = [];
protected override void OnInitialized() => _revoked = [.. PostedRevoked ?? []];
private void Toggle()
{
if ((Posted ?? _clicked) is not { } email)
{
return;
}
// The button's new name isn't read while it has focus; the announcement says what happened.
if (_revoked.Add(email))
{
Announcer.Announce($"Revoked the invite for {email}.");
}
else
{
_revoked.Remove(email);
Announcer.Announce($"Restored the invite for {email}.");
}
}
}Static: Revoke posts without a full reload, and the message in the response is read.
Every call is read, the same words twice included. AddIzzyBlazor() registers the service.
On interactive pages, the message goes to the browser at once. On static pages, it renders in the response, so put an AnnouncerRegion in your layout. A ToastRegion already includes one, so a layout with toasts needs nothing more.
A redirect drops the message. To tell users something after post-redirect-get, show a toast, which follows them to the next page.
With JavaScript off, messages aren't read. Put the outcome where focus lands instead: a Form's errors take focus after a failed post.
Announce in response to an action, not in OnInitialized, which runs twice on a prerendered interactive page.
Interrupting
Both are polite by default: the screen reader finishes what it's saying first. For an error that stops the task, set Assertive on a LiveRegion, or pass assertive: true to Announce. An assertive message cuts off what's being read, so keep it for errors.
Unlike a polite one, an assertive LiveRegion is read when it appears with text, so leave its Text empty until there's an error. Set Assertive once: screen readers don't reliably notice it changing.
<LiveRegion Text="uploadError" Assertive />
Announcer.Announce("Couldn't save: you're offline.", assertive: true);Mode support
| Feature | Static | Interactive |
|---|---|---|
| Hidden text read when it changes (LiveRegion) | Yes | Yes |
| Messages from C# (Announcer), the same words twice included | Yes | Yes |
| Polite or assertive | Yes | Yes |
Static: static server-side rendering, with no circuit and no WebAssembly. Interactive: Server, WebAssembly or Auto.
Without JavaScript
Every page starts as plain HTML: before IzzyBlazor's script loads on a static page, while an interactive page prerenders, and with JavaScript off. With JavaScript off, the text changes only with a new page, and text a page loads with isn't read.
Accessibility
- Polite (
role="status"): read when the screen reader is done with what it's saying.Assertive(role="alert") interrupts; keep it for errors that stop the task. - It's read when its text changes. The same text again isn't read: it describes the page, and nothing changed.
- Put it on the page from the start. A polite region's first text isn't read: screen readers only watch regions that were already there. An assertive one is read when it appears with text, so give it text only when there's an error to report.
- Set
Assertiveonce: screen readers don't reliably notice a region's role changing. - The whole text is read each time (
aria-atomic), not just the part that changed.
Parameters
Plus 4 common props.
Full APISee also
Announcer- Alert: shows a status message about part of a page.