Overview
Toast displays a brief, temporary notification to the user. It’s typically used to provide feedback about an operation or to communicate important information.Features
- Automatically closes after a configurable timeout
- Supports closing via pointer, focus, or programmatically
- Supports swipe gestures to dismiss
- Exposes CSS variables for flexible animations
- Manages focus within and across toasts
- Respects
prefers-reduced-motion
Installation
Anatomy
API Reference
Provider
The provider that wraps your toasts and viewport. It usually wraps the application.An author-localized label for each toast. Used to help screen reader users associate the interruption with a toast.
Time in milliseconds that each toast should remain visible for.
Direction of pointer swipe that should close the toast.
Distance in pixels that the swipe must pass before a close is triggered.
Viewport
The fixed area where toasts appear. Users can jump to the viewport by pressing a hotkey.The keys to use as the keyboard shortcut that will move focus to the toast viewport.
An author-localized label for the toast viewport to provide context for screen reader users.
Root
The toast that automatically closes. It should not be held open to acquire a user response.Control the sensitivity of the toast for accessibility purposes. For toasts that are the result of a user action, use
foreground. Toasts generated from background tasks should use background.Time in milliseconds that toast should remain visible for. Overrides value from provider.
The controlled open state of the toast.
The open state of the toast when it is initially rendered. Use when you do not need to control its open state.
Event handler called when the open state changes.
Event handler called when the escape key is pressed.
Event handler called when the dismiss timer is paused.
Event handler called when the dismiss timer is resumed.
Event handler called when starting a swipe interaction.
Event handler called during a swipe interaction.
Event handler called at the end of a swipe interaction.
Used to force mounting when more control is needed.
Title
An optional title for the toast.Description
The toast message.Action
An action that is safe to ignore to ensure users are not expected to complete tasks with unexpected side effects as a result of a time limit.A short description for screen readers announcing the action.
Close
A button that closes the toast.Examples
Basic Usage
Multiple Toasts
Data Attributes
Root
data-state-"open"or"closed"data-swipe-"start","move","cancel", or"end"data-swipe-direction-"up","down","left", or"right"
CSS Variables
Root
--radix-toast-swipe-move-x- The offset during a swipe (horizontal)--radix-toast-swipe-move-y- The offset during a swipe (vertical)--radix-toast-swipe-end-x- The final offset of a swipe (horizontal)--radix-toast-swipe-end-y- The final offset of a swipe (vertical)
Keyboard Interactions
F8- Focuses the toast viewport (configurable viahotkeyprop)Tab- Moves focus to the next focusable elementShift + Tab- Moves focus to the previous focusable elementSpace- When focus is on an action or close button, closes the toastEnter- When focus is on an action or close button, closes the toastEscape- Closes the toast