Feedback

Toast

Brief news about something that just happened, shown without interrupting.

Installation

npx sinaui add toast

Examples

Default

For news that needs no color. Hover or focus a toast and its timer pauses.

<script lang="ts">
	import Button from '#lib/ui/Button.svelte';
	import { toast } from '#lib/ui/toast/index.js';
</script>

<!-- Add <Toaster /> once, in your root layout. -->
<Button variant="secondary" onclick={() => toast('Manuscript added to your reading list.')}>
	Show a toast
</Button>

Success

When something worked, with a line of detail.

<script lang="ts">
	import Button from '#lib/ui/Button.svelte';
	import { toast } from '#lib/ui/toast/index.js';
</script>

<!-- Add <Toaster /> once, in your root layout. -->
<Button
	variant="secondary"
	onclick={() =>
		toast.success('Copy commissioned', {
			description: 'A scribe in Baghdad will finish it within the season.'
		})}
>
	Commission a copy
</Button>

Error

When something failed: say what happened and what to do.

<script lang="ts">
	import Button from '#lib/ui/Button.svelte';
	import { toast } from '#lib/ui/toast/index.js';
</script>

<!-- Add <Toaster /> once, in your root layout. -->
<Button
	variant="secondary"
	onclick={() =>
		toast.error('The Córdoba library is closed for the night.', {
			description: 'Requests reopen at dawn prayer.'
		})}
>
	Send to Córdoba
</Button>

With an action

One action, such as Undo. Toasts with an action stay twice as long.

3 loans active

<script lang="ts">
	import Button from '#lib/ui/Button.svelte';
	import { toast } from '#lib/ui/toast/index.js';

	let loans = $state(3);

	function withdraw() {
		loans -= 1;
		toast('Loan withdrawn.', { action: { label: 'Undo', onclick: () => (loans += 1) } });
	}
</script>

<Button variant="danger" onclick={withdraw} disabled={loans === 0}>Withdraw a loan</Button>
<p class="count" role="status">{loans} loans active</p>

<style>
	.count {
		margin: 0;
		color: var(--ui-muted);
	}
</style>

API

CallDoes
toast(message, options?)Shows a toast; returns its id.
toast.success(…) / toast.error(…)With an icon, and the kind spoken to screen readers.
dismiss(id)Removes one early.
optionsdescription, action: { label, onclick }, duration (ms)

Accessibility

  • Toasts live in a labeled region that's always in the page, so screen readers announce each one politely without moving focus.
  • The countdown pauses while any toast is hovered or focused and while the tab is hidden (WCAG 2.2.1); errors stay 8 seconds, others 5, doubled when there's an action.
  • Every toast has a close button. Anything people must act on belongs in a Dialog, not a toast.
  • Closing a focused toast moves focus to the next one, or back to where you were: it never drops to the top of the page.
  • Enter, exit and restacking move with transforms only, and switch off with reduced motion.
KeyAction
F6Jumps to the newest toast, and back to where you were.
TabMoves between a toast's buttons and on to the next toast.
Introduction
Theming
Changelog
Button
Action button
Confirm button
Copy button
Hold to confirm
Split button
Calendar
Checkbox
Color picker
Combobox
Date picker
Date range picker
File drop
Form
Input
Mention input
Multi select
Number field
OTP input
Password input
Phone input
Radio cards
Radio group
Rich text editor
Search field
Segmented control
Select
Signature pad
Slider
Switch
Tag input
Upload
Wheel picker
Textarea
Time field
Toggle group
Toolbar
Alert dialog
Command palette
Context menu
Dialog
Drawer
Dropdown
Hover card
Popover
Tooltip
Announcement bar
Alert
Empty state
Meter
Progress
Rolling number
Skeleton
Spinner
Toast
Avatar
Avatar group
Badge
Card
Carousel
Chart
Chat
Code block
Data table
Folder
Kbd
Mind map
Resizable panels
Scroll area
Separator
Sortable
Table
Tag group
Virtual list
Audio player
Image
Image compare
Video
Visualizer
Breadcrumb
File tree
Menubar
Navigation menu
Pagination
Sidebar layout
Stepper
Tabs
Alarm clock
Clock
Dynamic island
Fluid orb
Hourglass
Stopwatch
Timer
AI chat
AI media
Auth
Board
Booking
Dashboard
File explorer
Messaging
Notifications
Settings
Team
Overview
Pricing
Agent chat
Calendar
Voice agent
Mail inbox
CMS
Blog
Marketing site
E-commerce
AI agents
SaaS landing page
SaaS app
Accordion
Dark theme
Light theme