Skip to main content

Appearance and variants

A toast has one of five variants (primary, success, info, warning, or danger) and one of two appearances. Subtle colours the whole toast. Outline keeps a neutral card and colours only the icon. Choose them with the variant and appearance options. The defaults are primary and outline. A toast can have an icon, a title, a message, an action link, and a close button; each of them is optional.

Subtle

Primary

A highlighted message for you.

Action

Success

Your changes were saved.

Action

Info

A new version is available.

Action

Warning

Storage is almost full.

Action

Outline

Primary

A highlighted message for you.

Action

Success

Your changes were saved.

Action

Info

A new version is available.

Action

Warning

Storage is almost full.

Action

Show a toast

Call Starkit.makeToast(config) to show a toast. It returns the id of the toast. You can call it from an Alpine expression (x-on:click), from an onclick attribute, or from your own script. Each button below shows a toast of its variant. The toast closes after 5 seconds, when its close button is pressed, or when its action link is clicked.

Position

The position option decides where a toast appears: top-left, top-center, top-right (the default), bottom-left, bottom-center, or bottom-right. Toasts with the same position stack in one wrapper. The wrapper is created with its first toast and removed when its last toast closes.

Helpers

Four helpers manage all toasts. They are on window.Starkit, so any JavaScript can call them: an Alpine expression, an onclick attribute, or your own script. makeToast and updateToast take the options below.

Helpers

Helper Returns What it does
makeToast(config) string Shows a toast and returns its id.
updateToast(id, config) nothing Changes the options of a toast that is still shown. The fields you pass replace the old ones, and the timer starts again.
dismissToast(id) nothing Closes one toast by its id.
clearToasts() nothing Closes all toasts.

Options

Option Type Default Description
title string none The title of the toast.
message string none The message of the toast.
actionText string none The text of the action link. Without it there is no action link.
actionLink string # The URL the action link opens. Clicking the link also closes the toast.
actionTarget string none The target of the action link, for example _blank. With _blank, the link also gets rel="noopener noreferrer".
icon string none Font Awesome classes, for example fa-solid fa-star. Without an icon, none is shown.
dismissible boolean false Shows a close button.
duration number 5000 How long the toast stays, in milliseconds. 0 keeps it until it is closed.
position string top-right top-left, top-center, top-right, bottom-left, bottom-center, or bottom-right.
variant string primary primary, success, info, warning, or danger.
appearance string outline subtle or outline.