Toast
A toast is a short message about something that just happened, such as a saved draft or a failed upload. Your app shows one with a single call to showToast(), and Chameleon places it, times it, and removes it. You never put a toast on the page yourself, but you can restyle every toast with its CSS tokens.
Toasts in depth
When to use one
Use a toast to confirm something the user just did, or to report work that finished in the background: "Draft saved", "Message sent", "The upload failed". A toast appears over the page without taking focus, and it leaves on its own, so the user carries on with what they were doing.
Use a dialog when the user must answer before going on, and a card for a message that has to stay on the page.
Try it
Each button shows a toast. Save sets an overline, a variant, and an icon, Send passes its text alone, and Upload keeps its toast on screen until you close it.
Options
showToast() takes a string, which becomes the toast's text, or an object with these options. Only content is required. An option you leave out takes its default from app configuration, where one exists.
| Option | Type | Default | What it does |
|---|---|---|---|
content |
A string of HTML, a DOM node, or a TrustedHTML value |
None | The message. A string is read as HTML, so escape any text you didn't write, or pass a node |
overline |
String | None | Short text above the message, such as "Saved" |
supportingText |
String | None | A line of text below the message |
trailingSupportingText |
String | None | Short text at the end of the toast, such as a time |
leadingIconName |
String | None | A Material Symbols icon at the start of the toast |
trailingIconName |
String | None | A Material Symbols icon at the end of the toast |
flipLeadingIconInRtl |
Boolean | false |
Mirrors the leading icon in a right-to-left layout |
flipTrailingIconInRtl |
Boolean | false |
Mirrors the trailing icon in a right-to-left layout |
variant |
ToastVariant: Primary, Secondary, Tertiary, Information, Success, Warning, Error, and a Container form of each, such as SuccessContainer |
defaultToastVariant, which ships as PrimaryContainer |
The toast's color role |
timeout |
A number of milliseconds | toastTimeout, which ships as 5000 |
How long the toast stays when it closes on a timer |
dismissMethod |
ToastDismissMethod: CloseButton, Timer, CloseButtonAndTimer |
defaultToastDismissMethod, which ships as CloseButtonAndTimer |
How the toast closes: with its close button alone, or with its close button or when its time runs out, whichever comes first. Timer works as CloseButtonAndTimer, because every toast that closes by itself shows a close button |
position |
ToastPosition, one of nine values |
toastAnchor, which ships as StartEnd |
Where in the window the toast appears |
density |
Density: Standard, Dense1 to Dense4 |
toastDensity, which ships as Standard |
How compact the toast is |
waveShape |
ProgressWaveShape: Flat, Wavy |
defaultToastProgressWaveShape, which ships as Flat |
The shape of the bar that counts down the toast's time |
cssClass |
String | None | Classes for the toast, for styling one kind of toast with its own tokens |
cssStyle |
String | None | CSS declarations for the toast, such as one of its tokens |
overline, supportingText, and trailingSupportingText are always shown as text, never as HTML. How a toast appears and leaves comes from toastAnimation in app configuration, for every toast at once: Fade, Slide, or None.
Positions
A position names the block axis first, then the inline axis. In a left-to-right layout:
| Position | Where |
|---|---|
StartStart, StartCenter, StartEnd |
Top left, top center, top right |
CenterStart, CenterCenter, CenterEnd |
Middle left, the middle of the window, middle right |
EndStart, EndCenter, EndEnd |
Bottom left, bottom center, bottom right |
A right-to-left layout swaps left and right. App configuration's toastAnchor takes the four corners only, so a center is a choice you make for one toast, such as an error you show beside a dialog in the middle of the window.
Several at once
- Every call shows its toast at once. Chameleon doesn't hold toasts back in a queue, and it sets no limit on how many show together.
- Toasts at the same position stack, and the newest sits farthest from the window's edge. When one leaves, the others move along to close the gap.
- Toasts at different positions form separate stacks.
- When you change
toastAnchor, toasts on screen that use it move to the new corner. A toast that set its ownpositionstays where it is. - When a modal dialog opens, toasts on screen move into it, so the user can still close them, and they move back when it closes.
How long it stays
- With
TimerorCloseButtonAndTimer, a bar along the toast counts down itstimeout, and the toast leaves when the time runs out. - The countdown pauses while the mouse pointer is over the toast, while focus is inside it and while the page is hidden, then carries on with the time that was left. For a message the user needs time to read, use
CloseButtonor a longertimeout. - A toast with an action, such as Undo, never leaves on its own and shows no bar. The Web components tab shows how to add one.
- With
CloseButton, the toast shows no bar and stays until the user closes it. - When the user's system asks for reduced motion, toasts appear and leave without animating, and the bar holds still. The toast still leaves when its time runs out.
How it closes
- Its close button closes it. Every toast shows one at its end.
- Escape closes it while focus is inside the toast. Inside a modal dialog, Escape closes the toast and leaves the dialog open.
- When a toast that has focus closes, focus moves to the next toast, or back to where the user was before reaching the toasts.
- Its timer closes it, with
TimerorCloseButtonAndTimer, unless it has an action.
showToast() returns nothing, and Chameleon gives your code no way to close a toast once it's shown. Choose a timeout or a dismissMethod that fits the message instead. A toast with an action stays until the user closes it, whether or not they used the action.
Show a toast
Import showToast() from the package and call it wherever something happens that the user should know about.
import { showToast, ToastVariant } from "@materia-technologies-inc/chameleon-components-web";
showToast("Message sent");
showToast({
overline: "Saved",
content: "Your changes are safe",
variant: ToastVariant.Success,
leadingIconName: "check",
});
Text you didn't write
content is read as HTML. For text that comes from a user or a server, pass a DOM node whose text you set, or put the text in overline or supportingText, which are never read as HTML. A page that enforces Trusted Types refuses a string of markup, so pass a node or a TrustedHTML value from your own policy there.
import { showToast } from "@materia-technologies-inc/chameleon-components-web";
const content = document.createElement("span");
content.textContent = `${fileName} uploaded`;
showToast({ content });
Offer an action
To offer an action, such as Undo or Retry, pass a document fragment that holds the message and a button with slot="action". The button sits below the text, at the end of the toast. A toast with an action never closes by itself, so the user can always reach it, with F8 or Tab. It stays until the user closes it.
import { ButtonVariant, showToast } from "@materia-technologies-inc/chameleon-components-web";
const content = document.createDocumentFragment();
content.append("Message archived");
const undo = document.createElement("cw-button");
undo.slot = "action";
undo.setAttribute("variant", ButtonVariant.Text);
undo.textContent = "Undo";
undo.addEventListener("click", restoreMessage);
content.append(undo);
showToast({ content });
One toast in its own place
Give a toast its own position to show it somewhere other than the app's corner, such as beside a dialog in the middle of the window.
import { showToast, ToastDismissMethod, ToastPosition, ToastVariant } from "@materia-technologies-inc/chameleon-components-web";
showToast({
content: "Those credentials weren't recognized",
variant: ToastVariant.Error,
position: ToastPosition.CenterCenter,
dismissMethod: ToastDismissMethod.CloseButton,
});
Defaults for every toast
Set where toasts appear and how long they stay with setAppConfiguration(). App configuration lists every toast setting.
import { Corner, setAppConfiguration } from "@materia-technologies-inc/chameleon-components-web";
setAppConfiguration({ toastAnchor: Corner.EndEnd, toastTimeout: 8000 });
React apps call the same showToast(), imported from the React package. There's no toast component, provider, or hook to add.
Show a toast
Call showToast() from an event handler, an effect, or any code that runs after the work it reports.
import { CrButton, showToast, ToastVariant } from "@materia-technologies-inc/chameleon-components-react";
export function SaveButton({ onSave }: { onSave: () => Promise<void> }) {
async function save() {
await onSave();
showToast({ overline: "Saved", content: "Your changes are safe", variant: ToastVariant.Success });
}
return <CrButton onClick={save}>Save</CrButton>;
}
showToast() takes every option on the Overview tab, with the same defaults. An action, such as Undo, is added the same way as on the Web components tab: a document fragment whose button has slot="action".
Text, not JSX
content takes a string of HTML, a DOM node, or a TrustedHTML value. It doesn't render a React element. For text that comes from a user or a server, put it in overline or supportingText, which are never read as HTML, or pass a DOM node whose text you set.
import { showToast } from "@materia-technologies-inc/chameleon-components-react";
const content = document.createElement("span");
content.textContent = `${fileName} uploaded`;
showToast({ content });
Defaults for every toast
Set where toasts appear and how long they stay with setAppConfiguration(), from the same package. App configuration lists every toast setting.
Blazor apps show a toast through IChameleonToastService, which AddChameleonServices() registers. Inject it into a component and call ShowToast().
Show a toast
ShowToast() comes in two forms. The first takes a severity, BlazorToastLevel.Info, Success, Warning, or Error, and picks the toast's variant, its icon, and an overline that names the level.
@inject IChameleonToastService ToastService
<CbButton OnClick="SaveAsync">Save</CbButton>
@code {
private async Task SaveAsync()
{
await ToastService.ShowToast("Your changes are safe", BlazorToastLevel.Success);
}
}
The overline it picks is the level's name in English, such as "Success". Pass heading to word it yourself, or to translate it. It also takes dismissMethod and timeout, which work as in the second form.
The second form takes the toast's parts one by one. Only content is required.
await ToastService.ShowToast(
"Your changes are safe",
overline: "Saved",
leadingIconName: "check",
variant: ToastVariant.Success,
timeout: 8000);
| Parameter | What it does |
|---|---|
content |
The message, a string of HTML. Escape any text you didn't write |
dismissMethod |
ToastDismissMethod.CloseButton, Timer, or CloseButtonAndTimer |
cssClass |
Classes for the toast, for styling one kind of toast with its own tokens |
cssStyle |
CSS declarations for the toast, such as one of its tokens |
leadingIconName |
A Material Symbols icon at the start of the toast |
overline |
Short text above the message |
timeout |
How long the toast stays, in milliseconds, when it closes on a timer |
trailingIconName |
A Material Symbols icon at the end of the toast |
trailingSupportingText |
Short text at the end of the toast, such as a time |
variant |
The toast's color role, a ToastVariant |
The Blazor service has no per-toast position, supporting text, density, wave shape, icon flipping, or action. Set the position for every toast in the service's configuration, below, and density and wave shape in app configuration.
Configure the service
Assign a ChameleonToastServiceConfiguration in the options of AddChameleonServices().
using Chameleon.Blazor;
builder.Services.AddChameleonServices(options =>
{
options.ChameleonToastServiceConfiguration = new ChameleonToastServiceConfiguration
{
Position = BlazorToastPosition.BottomCenter,
Timeout = 8000,
CloseMethod = ToastDismissMethod.CloseButtonAndTimer,
};
});
| Setting | Default | What it does |
|---|---|---|
Position |
null, which follows app configuration's ToastAnchor |
Where every toast from the service appears: TopLeft, TopCenter, TopRight, CenterLeft, CenterCenter, CenterRight, BottomLeft, BottomCenter, or BottomRight. A right-to-left layout swaps left and right |
Timeout |
3000 |
How long a toast stays, in milliseconds, when it doesn't pass its own timeout |
CloseMethod |
ToastDismissMethod.CloseButtonAndTimer |
How a toast closes when it doesn't pass its own dismissMethod |
The service always sends a timeout and a close method, so app configuration's ToastTimeout and DefaultToastDismissMethod don't reach the toasts it shows. Set Timeout and CloseMethod here instead.
Set the tokens
A toast takes its colors, type, and spacing from --ct-toast-* tokens. Chameleon adds toasts at the end of <body>, or inside an open modal dialog, so a token you set on your app's own container doesn't reach them. Set the tokens on :root, or on cw-toast to style every toast and nothing else.
cw-toast {
--ct-toast-container-color: var(--ct-sys-color-inverse-surface);
--ct-toast-label-text-color: var(--ct-sys-color-inverse-on-surface);
}
To style one kind of toast, pass a class in cssClass and set the tokens on that class. For a single toast, pass the declarations in cssStyle.
cw-toast.offline {
--ct-toast-container-color: var(--ct-sys-color-surface-container-highest);
}
The tables below list every token. Each variant has its own tokens, and a variant's token falls back to the token of the same name without a variant, so --ct-toast-container-color changes every variant at once.
Each attribute value has its own tokens; a cell shows its token's value, and selecting the cell shows the token's fallback path, with each name and value ready to copy. For example, the primary-container column's action-hover-label-text-color row is --ct-toast-primary-container-action-hover-label-text-color, which defaults to same as --ct-toast-action-hover-label-text-color.
Variant
| Name | primary | secondary | tertiary | information | success | warning | error | primary-container | secondary-container | tertiary-container | information-container | success-container | warning-container | error-container |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
action-hover-label-text-color | same as --ct-toast-action-hover-label-text-color --ct-toast-primary-action-hover-label-text-color | same as --ct-toast-action-hover-label-text-color --ct-toast-secondary-action-hover-label-text-color | same as --ct-toast-action-hover-label-text-color --ct-toast-tertiary-action-hover-label-text-color | same as --ct-toast-action-hover-label-text-color --ct-toast-information-action-hover-label-text-color | same as --ct-toast-action-hover-label-text-color --ct-toast-success-action-hover-label-text-color | same as --ct-toast-action-hover-label-text-color --ct-toast-warning-action-hover-label-text-color | same as --ct-toast-action-hover-label-text-color --ct-toast-error-action-hover-label-text-color | same as --ct-toast-action-hover-label-text-color --ct-toast-primary-container-action-hover-label-text-color | same as --ct-toast-action-hover-label-text-color --ct-toast-secondary-container-action-hover-label-text-color | same as --ct-toast-action-hover-label-text-color --ct-toast-tertiary-container-action-hover-label-text-color | same as --ct-toast-action-hover-label-text-color --ct-toast-information-container-action-hover-label-text-color | same as --ct-toast-action-hover-label-text-color --ct-toast-success-container-action-hover-label-text-color | same as --ct-toast-action-hover-label-text-color --ct-toast-warning-container-action-hover-label-text-color | same as --ct-toast-action-hover-label-text-color --ct-toast-error-container-action-hover-label-text-color |
action-label-text-color | same as --ct-toast-action-label-text-color --ct-toast-primary-action-label-text-color | same as --ct-toast-action-label-text-color --ct-toast-secondary-action-label-text-color | same as --ct-toast-action-label-text-color --ct-toast-tertiary-action-label-text-color | same as --ct-toast-action-label-text-color --ct-toast-information-action-label-text-color | same as --ct-toast-action-label-text-color --ct-toast-success-action-label-text-color | same as --ct-toast-action-label-text-color --ct-toast-warning-action-label-text-color | same as --ct-toast-action-label-text-color --ct-toast-error-action-label-text-color | same as --ct-toast-action-label-text-color --ct-toast-primary-container-action-label-text-color | same as --ct-toast-action-label-text-color --ct-toast-secondary-container-action-label-text-color | same as --ct-toast-action-label-text-color --ct-toast-tertiary-container-action-label-text-color | same as --ct-toast-action-label-text-color --ct-toast-information-container-action-label-text-color | same as --ct-toast-action-label-text-color --ct-toast-success-container-action-label-text-color | same as --ct-toast-action-label-text-color --ct-toast-warning-container-action-label-text-color | same as --ct-toast-action-label-text-color --ct-toast-error-container-action-label-text-color |
action-pressed-label-text-color | same as --ct-toast-action-pressed-label-text-color --ct-toast-primary-action-pressed-label-text-color | same as --ct-toast-action-pressed-label-text-color --ct-toast-secondary-action-pressed-label-text-color | same as --ct-toast-action-pressed-label-text-color --ct-toast-tertiary-action-pressed-label-text-color | same as --ct-toast-action-pressed-label-text-color --ct-toast-information-action-pressed-label-text-color | same as --ct-toast-action-pressed-label-text-color --ct-toast-success-action-pressed-label-text-color | same as --ct-toast-action-pressed-label-text-color --ct-toast-warning-action-pressed-label-text-color | same as --ct-toast-action-pressed-label-text-color --ct-toast-error-action-pressed-label-text-color | same as --ct-toast-action-pressed-label-text-color --ct-toast-primary-container-action-pressed-label-text-color | same as --ct-toast-action-pressed-label-text-color --ct-toast-secondary-container-action-pressed-label-text-color | same as --ct-toast-action-pressed-label-text-color --ct-toast-tertiary-container-action-pressed-label-text-color | same as --ct-toast-action-pressed-label-text-color --ct-toast-information-container-action-pressed-label-text-color | same as --ct-toast-action-pressed-label-text-color --ct-toast-success-container-action-pressed-label-text-color | same as --ct-toast-action-pressed-label-text-color --ct-toast-warning-container-action-pressed-label-text-color | same as --ct-toast-action-pressed-label-text-color --ct-toast-error-container-action-pressed-label-text-color |
action-state-layer-color | same as --ct-toast-action-state-layer-color --ct-toast-primary-action-state-layer-color | same as --ct-toast-action-state-layer-color --ct-toast-secondary-action-state-layer-color | same as --ct-toast-action-state-layer-color --ct-toast-tertiary-action-state-layer-color | same as --ct-toast-action-state-layer-color --ct-toast-information-action-state-layer-color | same as --ct-toast-action-state-layer-color --ct-toast-success-action-state-layer-color | same as --ct-toast-action-state-layer-color --ct-toast-warning-action-state-layer-color | same as --ct-toast-action-state-layer-color --ct-toast-error-action-state-layer-color | same as --ct-toast-action-state-layer-color --ct-toast-primary-container-action-state-layer-color | same as --ct-toast-action-state-layer-color --ct-toast-secondary-container-action-state-layer-color | same as --ct-toast-action-state-layer-color --ct-toast-tertiary-container-action-state-layer-color | same as --ct-toast-action-state-layer-color --ct-toast-information-container-action-state-layer-color | same as --ct-toast-action-state-layer-color --ct-toast-success-container-action-state-layer-color | same as --ct-toast-action-state-layer-color --ct-toast-warning-container-action-state-layer-color | same as --ct-toast-action-state-layer-color --ct-toast-error-container-action-state-layer-color |
active-indicator-color | same as --ct-toast-active-indicator-color --ct-toast-primary-active-indicator-color | same as --ct-toast-active-indicator-color --ct-toast-secondary-active-indicator-color | same as --ct-toast-active-indicator-color --ct-toast-tertiary-active-indicator-color | same as --ct-toast-active-indicator-color --ct-toast-information-active-indicator-color | same as --ct-toast-active-indicator-color --ct-toast-success-active-indicator-color | same as --ct-toast-active-indicator-color --ct-toast-warning-active-indicator-color | same as --ct-toast-active-indicator-color --ct-toast-error-active-indicator-color | same as --ct-toast-active-indicator-color --ct-toast-primary-container-active-indicator-color | same as --ct-toast-active-indicator-color --ct-toast-secondary-container-active-indicator-color | same as --ct-toast-active-indicator-color --ct-toast-tertiary-container-active-indicator-color | same as --ct-toast-active-indicator-color --ct-toast-information-container-active-indicator-color | same as --ct-toast-active-indicator-color --ct-toast-success-container-active-indicator-color | same as --ct-toast-active-indicator-color --ct-toast-warning-container-active-indicator-color | same as --ct-toast-active-indicator-color --ct-toast-error-container-active-indicator-color |
close-button-hover-icon-color | same as --ct-toast-close-button-hover-icon-color --ct-toast-primary-close-button-hover-icon-color | same as --ct-toast-close-button-hover-icon-color --ct-toast-secondary-close-button-hover-icon-color | same as --ct-toast-close-button-hover-icon-color --ct-toast-tertiary-close-button-hover-icon-color | same as --ct-toast-close-button-hover-icon-color --ct-toast-information-close-button-hover-icon-color | same as --ct-toast-close-button-hover-icon-color --ct-toast-success-close-button-hover-icon-color | same as --ct-toast-close-button-hover-icon-color --ct-toast-warning-close-button-hover-icon-color | same as --ct-toast-close-button-hover-icon-color --ct-toast-error-close-button-hover-icon-color | same as --ct-toast-close-button-hover-icon-color --ct-toast-primary-container-close-button-hover-icon-color | same as --ct-toast-close-button-hover-icon-color --ct-toast-secondary-container-close-button-hover-icon-color | same as --ct-toast-close-button-hover-icon-color --ct-toast-tertiary-container-close-button-hover-icon-color | same as --ct-toast-close-button-hover-icon-color --ct-toast-information-container-close-button-hover-icon-color | same as --ct-toast-close-button-hover-icon-color --ct-toast-success-container-close-button-hover-icon-color | same as --ct-toast-close-button-hover-icon-color --ct-toast-warning-container-close-button-hover-icon-color | same as --ct-toast-close-button-hover-icon-color --ct-toast-error-container-close-button-hover-icon-color |
close-button-pressed-icon-color | same as --ct-toast-close-button-pressed-icon-color --ct-toast-primary-close-button-pressed-icon-color | same as --ct-toast-close-button-pressed-icon-color --ct-toast-secondary-close-button-pressed-icon-color | same as --ct-toast-close-button-pressed-icon-color --ct-toast-tertiary-close-button-pressed-icon-color | same as --ct-toast-close-button-pressed-icon-color --ct-toast-information-close-button-pressed-icon-color | same as --ct-toast-close-button-pressed-icon-color --ct-toast-success-close-button-pressed-icon-color | same as --ct-toast-close-button-pressed-icon-color --ct-toast-warning-close-button-pressed-icon-color | same as --ct-toast-close-button-pressed-icon-color --ct-toast-error-close-button-pressed-icon-color | same as --ct-toast-close-button-pressed-icon-color --ct-toast-primary-container-close-button-pressed-icon-color | same as --ct-toast-close-button-pressed-icon-color --ct-toast-secondary-container-close-button-pressed-icon-color | same as --ct-toast-close-button-pressed-icon-color --ct-toast-tertiary-container-close-button-pressed-icon-color | same as --ct-toast-close-button-pressed-icon-color --ct-toast-information-container-close-button-pressed-icon-color | same as --ct-toast-close-button-pressed-icon-color --ct-toast-success-container-close-button-pressed-icon-color | same as --ct-toast-close-button-pressed-icon-color --ct-toast-warning-container-close-button-pressed-icon-color | same as --ct-toast-close-button-pressed-icon-color --ct-toast-error-container-close-button-pressed-icon-color |
close-button-state-layer-color | same as --ct-toast-close-button-state-layer-color --ct-toast-primary-close-button-state-layer-color | same as --ct-toast-close-button-state-layer-color --ct-toast-secondary-close-button-state-layer-color | same as --ct-toast-close-button-state-layer-color --ct-toast-tertiary-close-button-state-layer-color | same as --ct-toast-close-button-state-layer-color --ct-toast-information-close-button-state-layer-color | same as --ct-toast-close-button-state-layer-color --ct-toast-success-close-button-state-layer-color | same as --ct-toast-close-button-state-layer-color --ct-toast-warning-close-button-state-layer-color | same as --ct-toast-close-button-state-layer-color --ct-toast-error-close-button-state-layer-color | same as --ct-toast-close-button-state-layer-color --ct-toast-primary-container-close-button-state-layer-color | same as --ct-toast-close-button-state-layer-color --ct-toast-secondary-container-close-button-state-layer-color | same as --ct-toast-close-button-state-layer-color --ct-toast-tertiary-container-close-button-state-layer-color | same as --ct-toast-close-button-state-layer-color --ct-toast-information-container-close-button-state-layer-color | same as --ct-toast-close-button-state-layer-color --ct-toast-success-container-close-button-state-layer-color | same as --ct-toast-close-button-state-layer-color --ct-toast-warning-container-close-button-state-layer-color | same as --ct-toast-close-button-state-layer-color --ct-toast-error-container-close-button-state-layer-color |
container-color | same as --ct-toast-container-color --ct-toast-primary-container-color | same as --ct-toast-container-color --ct-toast-secondary-container-color | same as --ct-toast-container-color --ct-toast-tertiary-container-color | same as --ct-toast-container-color --ct-toast-information-container-color | same as --ct-toast-container-color --ct-toast-success-container-color | same as --ct-toast-container-color --ct-toast-warning-container-color | same as --ct-toast-container-color --ct-toast-error-container-color | same as --ct-toast-container-color --ct-toast-primary-container-container-color | same as --ct-toast-container-color --ct-toast-secondary-container-container-color | same as --ct-toast-container-color --ct-toast-tertiary-container-container-color | same as --ct-toast-container-color --ct-toast-information-container-container-color | same as --ct-toast-container-color --ct-toast-success-container-container-color | same as --ct-toast-container-color --ct-toast-warning-container-container-color | same as --ct-toast-container-color --ct-toast-error-container-container-color |
label-text-color | same as --ct-toast-label-text-color --ct-toast-primary-label-text-color | same as --ct-toast-label-text-color --ct-toast-secondary-label-text-color | same as --ct-toast-label-text-color --ct-toast-tertiary-label-text-color | same as --ct-toast-label-text-color --ct-toast-information-label-text-color | same as --ct-toast-label-text-color --ct-toast-success-label-text-color | same as --ct-toast-label-text-color --ct-toast-warning-label-text-color | same as --ct-toast-label-text-color --ct-toast-error-label-text-color | same as --ct-toast-label-text-color --ct-toast-primary-container-label-text-color | same as --ct-toast-label-text-color --ct-toast-secondary-container-label-text-color | same as --ct-toast-label-text-color --ct-toast-tertiary-container-label-text-color | same as --ct-toast-label-text-color --ct-toast-information-container-label-text-color | same as --ct-toast-label-text-color --ct-toast-success-container-label-text-color | same as --ct-toast-label-text-color --ct-toast-warning-container-label-text-color | same as --ct-toast-label-text-color --ct-toast-error-container-label-text-color |
leading-icon-color | same as --ct-toast-leading-icon-color --ct-toast-primary-leading-icon-color | same as --ct-toast-leading-icon-color --ct-toast-secondary-leading-icon-color | same as --ct-toast-leading-icon-color --ct-toast-tertiary-leading-icon-color | same as --ct-toast-leading-icon-color --ct-toast-information-leading-icon-color | same as --ct-toast-leading-icon-color --ct-toast-success-leading-icon-color | same as --ct-toast-leading-icon-color --ct-toast-warning-leading-icon-color | same as --ct-toast-leading-icon-color --ct-toast-error-leading-icon-color | same as --ct-toast-leading-icon-color --ct-toast-primary-container-leading-icon-color | same as --ct-toast-leading-icon-color --ct-toast-secondary-container-leading-icon-color | same as --ct-toast-leading-icon-color --ct-toast-tertiary-container-leading-icon-color | same as --ct-toast-leading-icon-color --ct-toast-information-container-leading-icon-color | same as --ct-toast-leading-icon-color --ct-toast-success-container-leading-icon-color | same as --ct-toast-leading-icon-color --ct-toast-warning-container-leading-icon-color | same as --ct-toast-leading-icon-color --ct-toast-error-container-leading-icon-color |
overline-color | same as --ct-toast-overline-color --ct-toast-primary-overline-color | same as --ct-toast-overline-color --ct-toast-secondary-overline-color | same as --ct-toast-overline-color --ct-toast-tertiary-overline-color | same as --ct-toast-overline-color --ct-toast-information-overline-color | same as --ct-toast-overline-color --ct-toast-success-overline-color | same as --ct-toast-overline-color --ct-toast-warning-overline-color | same as --ct-toast-overline-color --ct-toast-error-overline-color | same as --ct-toast-overline-color --ct-toast-primary-container-overline-color | same as --ct-toast-overline-color --ct-toast-secondary-container-overline-color | same as --ct-toast-overline-color --ct-toast-tertiary-container-overline-color | same as --ct-toast-overline-color --ct-toast-information-container-overline-color | same as --ct-toast-overline-color --ct-toast-success-container-overline-color | same as --ct-toast-overline-color --ct-toast-warning-container-overline-color | same as --ct-toast-overline-color --ct-toast-error-container-overline-color |
supporting-text-color | same as --ct-toast-supporting-text-color --ct-toast-primary-supporting-text-color | same as --ct-toast-supporting-text-color --ct-toast-secondary-supporting-text-color | same as --ct-toast-supporting-text-color --ct-toast-tertiary-supporting-text-color | same as --ct-toast-supporting-text-color --ct-toast-information-supporting-text-color | same as --ct-toast-supporting-text-color --ct-toast-success-supporting-text-color | same as --ct-toast-supporting-text-color --ct-toast-warning-supporting-text-color | same as --ct-toast-supporting-text-color --ct-toast-error-supporting-text-color | same as --ct-toast-supporting-text-color --ct-toast-primary-container-supporting-text-color | same as --ct-toast-supporting-text-color --ct-toast-secondary-container-supporting-text-color | same as --ct-toast-supporting-text-color --ct-toast-tertiary-container-supporting-text-color | same as --ct-toast-supporting-text-color --ct-toast-information-container-supporting-text-color | same as --ct-toast-supporting-text-color --ct-toast-success-container-supporting-text-color | same as --ct-toast-supporting-text-color --ct-toast-warning-container-supporting-text-color | same as --ct-toast-supporting-text-color --ct-toast-error-container-supporting-text-color |
trailing-icon-color | same as --ct-toast-trailing-icon-color --ct-toast-primary-trailing-icon-color | same as --ct-toast-trailing-icon-color --ct-toast-secondary-trailing-icon-color | same as --ct-toast-trailing-icon-color --ct-toast-tertiary-trailing-icon-color | same as --ct-toast-trailing-icon-color --ct-toast-information-trailing-icon-color | same as --ct-toast-trailing-icon-color --ct-toast-success-trailing-icon-color | same as --ct-toast-trailing-icon-color --ct-toast-warning-trailing-icon-color | same as --ct-toast-trailing-icon-color --ct-toast-error-trailing-icon-color | same as --ct-toast-trailing-icon-color --ct-toast-primary-container-trailing-icon-color | same as --ct-toast-trailing-icon-color --ct-toast-secondary-container-trailing-icon-color | same as --ct-toast-trailing-icon-color --ct-toast-tertiary-container-trailing-icon-color | same as --ct-toast-trailing-icon-color --ct-toast-information-container-trailing-icon-color | same as --ct-toast-trailing-icon-color --ct-toast-success-container-trailing-icon-color | same as --ct-toast-trailing-icon-color --ct-toast-warning-container-trailing-icon-color | same as --ct-toast-trailing-icon-color --ct-toast-error-container-trailing-icon-color |
trailing-supporting-text-color | same as --ct-toast-trailing-supporting-text-color --ct-toast-primary-trailing-supporting-text-color | same as --ct-toast-trailing-supporting-text-color --ct-toast-secondary-trailing-supporting-text-color | same as --ct-toast-trailing-supporting-text-color --ct-toast-tertiary-trailing-supporting-text-color | same as --ct-toast-trailing-supporting-text-color --ct-toast-information-trailing-supporting-text-color | same as --ct-toast-trailing-supporting-text-color --ct-toast-success-trailing-supporting-text-color | same as --ct-toast-trailing-supporting-text-color --ct-toast-warning-trailing-supporting-text-color | same as --ct-toast-trailing-supporting-text-color --ct-toast-error-trailing-supporting-text-color | same as --ct-toast-trailing-supporting-text-color --ct-toast-primary-container-trailing-supporting-text-color | same as --ct-toast-trailing-supporting-text-color --ct-toast-secondary-container-trailing-supporting-text-color | same as --ct-toast-trailing-supporting-text-color --ct-toast-tertiary-container-trailing-supporting-text-color | same as --ct-toast-trailing-supporting-text-color --ct-toast-information-container-trailing-supporting-text-color | same as --ct-toast-trailing-supporting-text-color --ct-toast-success-container-trailing-supporting-text-color | same as --ct-toast-trailing-supporting-text-color --ct-toast-warning-container-trailing-supporting-text-color | same as --ct-toast-trailing-supporting-text-color --ct-toast-error-container-trailing-supporting-text-color |
Other tokens
| Token | Value |
|---|---|
--ct-toast-action-hover-label-text-color | same as --ct-toast-action-label-text-color --ct-toast-action-hover-label-text-color |
--ct-toast-action-label-text-color | --ct-sys-color-on-primary-container-hover --ct-toast-action-label-text-color |
--ct-toast-action-pressed-label-text-color | same as --ct-toast-action-label-text-color --ct-toast-action-pressed-label-text-color |
--ct-toast-action-state-layer-color | --ct-sys-color-on-primary-container-state-layer --ct-toast-action-state-layer-color |
--ct-toast-active-indicator-color | --ct-sys-color-on-primary-container --ct-toast-active-indicator-color |
--ct-toast-bottom-space | 12px --ct-toast-bottom-space |
--ct-toast-close-button-hover-icon-color | same as --ct-toast-trailing-icon-color --ct-toast-close-button-hover-icon-color |
--ct-toast-close-button-pressed-icon-color | same as --ct-toast-trailing-icon-color --ct-toast-close-button-pressed-icon-color |
--ct-toast-close-button-state-layer-color | --ct-sys-color-on-primary-container-state-layer --ct-toast-close-button-state-layer-color |
--ct-toast-container-color | --ct-sys-color-primary-container --ct-toast-container-color |
--ct-toast-container-elevation | 3 --ct-toast-container-elevation |
--ct-toast-disabled-opacity | 0.38 --ct-toast-disabled-opacity |
--ct-toast-label-text-color | --ct-sys-color-on-error-container --ct-toast-label-text-color |
--ct-toast-label-text-font | --ct-sys-typescale-body-large-font --ct-toast-label-text-font |
--ct-toast-label-text-line-height | --ct-sys-typescale-body-large-line-height --ct-toast-label-text-line-height |
--ct-toast-label-text-size | --ct-sys-typescale-body-large-size --ct-toast-label-text-size |
--ct-toast-label-text-tracking | --ct-sys-typescale-body-large-tracking --ct-toast-label-text-tracking |
--ct-toast-label-text-weight | --ct-sys-typescale-body-large-weight --ct-toast-label-text-weight |
--ct-toast-leading-icon-color | --ct-sys-color-on-error-container --ct-toast-leading-icon-color |
--ct-toast-leading-icon-size | 24px --ct-toast-leading-icon-size |
--ct-toast-leading-space | 16px --ct-toast-leading-space |
--ct-toast-one-line-container-height | 56px --ct-toast-one-line-container-height |
--ct-toast-outline-color | transparent --ct-toast-outline-color |
--ct-toast-outline-width | 0px --ct-toast-outline-width |
--ct-toast-overline-color | --ct-sys-color-on-error-container --ct-toast-overline-color |
--ct-toast-overline-font | --ct-sys-typescale-label-small-font --ct-toast-overline-font |
--ct-toast-overline-line-height | --ct-sys-typescale-label-small-line-height --ct-toast-overline-line-height |
--ct-toast-overline-size | --ct-sys-typescale-label-small-size --ct-toast-overline-size |
--ct-toast-overline-tracking | --ct-sys-typescale-label-small-tracking --ct-toast-overline-tracking |
--ct-toast-overline-weight | --ct-sys-typescale-label-small-weight --ct-toast-overline-weight |
--ct-toast-supporting-text-color | --ct-sys-color-on-error-container --ct-toast-supporting-text-color |
--ct-toast-supporting-text-font | --ct-sys-typescale-body-medium-font --ct-toast-supporting-text-font |
--ct-toast-supporting-text-line-height | --ct-sys-typescale-body-medium-line-height --ct-toast-supporting-text-line-height |
--ct-toast-supporting-text-size | --ct-sys-typescale-body-medium-size --ct-toast-supporting-text-size |
--ct-toast-supporting-text-tracking | --ct-sys-typescale-body-medium-tracking --ct-toast-supporting-text-tracking |
--ct-toast-supporting-text-weight | --ct-sys-typescale-body-medium-weight --ct-toast-supporting-text-weight |
--ct-toast-top-space | 12px --ct-toast-top-space |
--ct-toast-trailing-icon-color | --ct-sys-color-on-primary-container-hover --ct-toast-trailing-icon-color |
--ct-toast-trailing-icon-size | 24px --ct-toast-trailing-icon-size |
--ct-toast-trailing-space | 16px --ct-toast-trailing-space |
--ct-toast-trailing-supporting-text-color | --ct-sys-color-on-error-container --ct-toast-trailing-supporting-text-color |
--ct-toast-trailing-supporting-text-font | --ct-sys-typescale-label-small-font --ct-toast-trailing-supporting-text-font |
--ct-toast-trailing-supporting-text-line-height | --ct-sys-typescale-label-small-line-height --ct-toast-trailing-supporting-text-line-height |
--ct-toast-trailing-supporting-text-size | --ct-sys-typescale-label-small-size --ct-toast-trailing-supporting-text-size |
--ct-toast-trailing-supporting-text-tracking | --ct-sys-typescale-label-small-tracking --ct-toast-trailing-supporting-text-tracking |
--ct-toast-trailing-supporting-text-weight | --ct-sys-typescale-label-small-weight --ct-toast-trailing-supporting-text-weight |
How it's announced
- Toasts sit in a region named "Notifications (F8)", so screen reader users can find them by landmark and learn the shortcut. The name is in the language the toast region inherits, usually the page's
<html lang>. - Each toast is read politely, once the screen reader finishes what it's saying, a moment after the toast appears.
- The overline, the message, the supporting text and the action's name are read. Keep them short, and put the outcome first.
- A toast with an action also says how to reach it: "Press F8 to reach the action".
- A toast never takes focus. The user's place on the page doesn't move when one appears.
Keyboard
- F8 moves focus to the newest toast, and again to the next older one. Tab also reaches the toasts, after the rest of the page. Inside an open modal dialog, they join the dialog's own tab order.
- A focused toast shows a focus ring, in a color that stands out on every toast color, and is read by its message.
- From the toast, Tab reaches the close button, then the action.
- Escape closes the toast while focus is inside it. Inside a dialog, it closes the toast and leaves the dialog open.
- When a focused toast closes, focus moves to the next toast. When none is left, it goes back to where the user was before reaching the toasts. If that place is gone, focus goes to the nearest control before the toast, then after it, then the page's main landmark. It falls to the top of the page only when nothing else can take focus.
- The close button's name is translated, such as Schließen in German.
Timing
- The countdown pauses while the mouse pointer is over the toast, while focus is inside it, and while the page is hidden, then carries on with the time that was left.
- Every toast that closes by itself has a close button.
- A toast with an action never closes by itself.
Your part
- Give the user time. Offer a setting that turns auto-dismiss off (
CloseButton) or lengthens thetimeout, and raise toasts with the user's choice. - Never make a toast the only way to do something. A user may not reach it before it leaves.
- Keep toasts away from the controls people use most. A toast can cover the control that has focus.
- Say what the color says. An
Errortoast takes the theme's error color, and a user who can't see the color still needs to know. Name the outcome in the overline or the message, and add an icon.