1. framework components
  2. toast

Toast

Display brief messages to users.

Usage

This component acts as a Singleton. Implement a single instance of <Toast.Group> in the root scope your application, then trigger it anywhere on demand using a shared createToaster() instance.

svelte
<script lang="ts">
	import { toaster } from '/some/path/toaster.ts';
	import { Toast } from '@skeletonlabs/skeleton-svelte';
	import type { Snippet } from 'svelte';

	interface Props {
		children?: Snippet;
	}

	const props: Props = $props();
</script>

{@render props.children?.()}

<Toast.Group {toaster}>
	{#snippet children(toast)}
		<Toast toast={toast}>
			<Toast.Message>
			<Toast.Title>{toast.title}</Toast.Title>
			<Toast.Description>{toast.description}</Toast.Description>
			</Toast.Message>
			<Toast.CloseTrigger />
		</Toast>
	{/snippet}
</Toast.Group>
svelte
<script lang="ts">
	import { toaster } from '/some/path/toaster.ts';

	function onClickHandler() {
		toaster.info({ title: 'Example', description: 'This is a toast message.' });
	}

</script>

Triggers

Shorthand methods are available for toast triggers, including: info(), success(), warning(), and error().

Or use the generic create() method to trigger toasts of any type: info|success|warning|error.

ts
toaster.create({
	type: 'info',
	title: 'This is a toast',
	description: 'This is a toast description.',
});

Placement

Set the placement value in your createToaster instance to define the global screen position.

Overlap

Use the overlap option in your createToaster instance to enable overlapping toasts.

: ActionReactRaw }} client:visible>

Note: Hovering over the toast group will expand all the toasts.

Closable

Use the closable prop to toggle display of the close button.

Meta

Use the meta key to pass arbitrary data along with the toast instance. This can be used to display an icon for example.

Promise

Toasts support asynchronous updates using promises.

Anatomy

Here’s an overview of how the Toast component is structured in code:

svelte
<script lang="ts">
	import { Toast, createToaster } from '@skeletonlabs/skeleton-svelte';
</script>

<Toast.Group>
	<Toast>
		<Toast.Message>
			<Toast.Title />
			<Toast.Description />
		</Toast.Message>
		<Toast.CloseTrigger />
	</Toast>
</Toast.Group>

API Reference

Root

PropDefaultType
toastOptions<any>

elementSnippet<[HTMLAttributes<"div">]> | undefined

Render the element yourself

Context

PropDefaultType
childrenSnippet<[() => ToastApi<PropTypes, any>]>

Group

PropDefaultType
toasterToastStore<any>

childrenSnippet<[ToastProps<any>]> | undefined

elementSnippet<[HTMLAttributes<"div">]> | undefined

Render the element yourself

Message

PropDefaultType
elementSnippet<[HTMLAttributes<"div">]> | undefined

Render the element yourself

Title

PropDefaultType
elementSnippet<[HTMLAttributes<"div">]> | undefined

Render the element yourself

Description

PropDefaultType
elementSnippet<[HTMLAttributes<"div">]> | undefined

Render the element yourself

ActionTrigger

PropDefaultType
elementSnippet<[HTMLAttributes<"button">]> | undefined

Render the element yourself

CloseTrigger

PropDefaultType
elementSnippet<[HTMLAttributes<"button">]> | undefined

Render the element yourself

View page on GitHub