Skip to the content

Toast

Small notifications that come in at a corner of the window, wait and leave: "Message sent", "Link copied", "Something went wrong".

Become a member to unlock the full effect today.

Join now

Already a member? Sign in

Documentation

  1. Copy to Webflow

    Add Geist and Geist Mono to your site's fonts (Site settings, Fonts, Google Fonts) before pasting: Webflow removes any font your site has not installed.

  2. Add custom CSS

    The look of a toast is the toast-plate class of the paste and the classes inside it: restyle them in the Designer. The stack has no block: the Embed places it, and reads four variables you can set in a rule of your own on the body, --toast-line and --toast-error for the two colours of the line, --toast-width for the width of a toast and --toast-edge for its distance to the window. In the stack the Embed gives the plate the width of the stack, no margin, and a 28px cross for its close; everything else is yours. The rows are Link blocks, because Webflow has no button that holds layers.
  3. Add custom JS

  4. Use it on your own elements

    Custom attributes
    Select the element on the canvas and open the Settings panel. Under Custom attributes, add a pair: the name on the left, the value on the right.
    Custom attributeWhat it does
    data-toast-template Marks the toast written in the page: the model every toast is a copy of, with your classes. It takes no value: leave the value field empty. The engine hides it on the published page; the canvas of the Designer shows it, which is where it is restyled. The settings below go on it. Without one the engine builds a plain ink plate, and the settings are then set in the settings block.
    data-toast="Link copied." On what fires a toast: a button, a link, any element of the page, as many as you like. Its value is the words of the toast, fired when the element is pressed. Pressed again while its toast is there, it starts that toast again. Without any such element toasts are only fired from a script or by a form. [ Required ]
    data-toast-kind="success" Beside data-toast: the kind of that toast, info (a dot), success (a tick that draws itself) or error (a stroke and a line in the error colour, read at once by a screen reader). Without it, the kind of the setting kind. [ Optional ]
    data-toast-duration="3000" Beside data-toast: how long that toast stays, in milliseconds, 0 to keep it until it is dismissed. Without it, the setting duration, or errorDuration for an error. [ Optional ]
    data-toast-action="Undo" Beside data-toast: adds an action with this word to the toast. Pressed, it closes the toast and fires toast:action. [ Optional ]
    data-toast-href="#basket" Beside data-toast-action: where the action leads. Without it the action leads nowhere and only closes the toast. [ Optional ]
    data-toast-id="saved" Beside data-toast: names the toast. Two elements with the same id share one toast, which the second writes over. Without it each element has its own, started again when the element is pressed again. [ Optional ]
    data-toast-text In the template: the element the words of a toast are written in. It takes no value. Without it they are written in the template itself, in place of everything it holds. [ Optional ]
    data-toast-mark In the template: the box the mark is drawn in, a dot, a tick or a stroke. It takes no value. Without it a toast has no mark. [ Optional ]
    data-toast-action In the template, with no value: the link of an action. Only a toast that has an action shows it. [ Optional ]
    data-toast-close In the template: the close. It takes no value. Its word stays its name for a screen reader and a cross is drawn in its place. Without it a toast is still dismissed by Escape, by a swipe and by its time. [ Optional ]
    data-toast-sent="Thank you, Pam." On a form of the library (Form 01, Form 02): its own words for the toast of a send that succeeded. data-toast-failed does the same for a send that failed, and data-toast-forms="off" keeps that form from firing any. [ Optional ]
    data-toast-state Written by the engine. On the stack: open. On a toast: in while it arrives, out while it leaves. A toast also carries data-toast-kind, and data-toast-back when it stands behind the newest. Never written by hand; the stylesheet reads them, and so can a rule of yours. [ Optional ]
    Settings
    Every setting is a custom attribute too, added the same way and on the same element. An attribute always wins over the defaults written in the code.
    AttributeDefaultWhat it is
    data-toast-position bottom-right The corner of the window the toasts come in at. Options: bottom-right, bottom-left, bottom-center, top-right, top-left, top-center. Under 480 px of width the stack is always at the foot of the window, edge to edge.
    data-toast-max 3 How many toasts are on screen at once. A toast fired beyond that waits in a queue: the oldest toast on screen gives it its place once it has been seen for a second and a half, and a toast that waits for an answer or was told to stay keeps its own.
    data-toast-duration 5000 How long a toast stays, in milliseconds, which is also the time its line takes to leave.
    data-toast-error-duration 8000 How long a toast of the kind error stays, in milliseconds.
    data-toast-kind info The kind of a toast fired without one. Options: info, a dot; success, a tick that draws itself; error, a stroke in the error colour, a line of that colour, and an announcement that does not wait.
    data-toast-forms on Whether the forms of the library fire a toast when they are sent and when their send fails. Options: on; off. data-toast-forms="off" on one form leaves that form alone.
    data-toast-sent Message sent. The words of the toast when a form of the library is sent. Options: any text, in the language of the page. data-toast-sent on one form gives it its own.
    data-toast-failed The message could not be sent. The words of the toast when the send of a form fails. Options: any text. data-toast-failed on one form gives it its own.
    data-toast-label Notifications The name of the stack for a screen reader, which lists it among the regions of the page. Options: any text, in the language of the page.
    data-toast-key F8 The key that moves the focus to the newest toast, and back to where it was when pressed again. Options: the name of a key as the browser gives it, F8, F6; off for none.

What it does

Toast is a site utility component for Webflow and vanilla JavaScript, with no library. Also called toast notification, stacked toast notifications or toast with progress timer.

Small notifications that come in at a corner of the window, wait and leave: "Message sent", "Link copied", "Something went wrong". One line runs around each toast and is its clock: it draws itself around the plate when the toast arrives, then leaves it from its start, and the toast goes when the last of the line is gone. A toast that waits for an answer has a piece of that line going round, which becomes the whole line when "Sending" becomes "Sent". The time stops under the pointer, with the focus, under a finger and while the tab is hidden, and the line stops with it. Several toasts stack: an older one steps back behind the newest and shows a strip of itself, and the stack opens on hover, on focus or at a tap. A maximum number is on screen: toasts fired together come in one after the other, and the oldest gives its place to the one that waits. A toast is fired without code, by an attribute on any element, from JavaScript with Toast.show(), which returns the toast to update or dismiss, or by the forms of the library when they are sent or fail. It is dismissed by its cross, by a swipe on a touch screen, by Escape. Two live regions tell a screen reader, politely for information and at once for an error, and the focus is never taken. On a phone the stack is the full width of the foot of the window, above the keyboard. The toast itself is a block of the page, the template, so it is restyled like any other. No library. Pattern type toast notification, snackbar, alert.

Updated

Questions

Paste the component, then put the custom attribute data-toast on any button or link, with the words of the toast as its value. Pressing it fires the toast in the corner; data-toast-kind makes it a success or an error and data-toast-duration sets how long it stays, in milliseconds.

Yes. A line runs around each toast and leaves it over the duration, 5000 ms unless said otherwise, and the toast goes when the line is gone. The line and the time stop while the pointer is on the stack, while the focus is in it, under a finger and while the tab is hidden.

Toast.show({ text: 'Sending', kind: 'loading' }) returns the toast; call its update({ text: 'Sent.', kind: 'success' }) when the request answers, or with kind: 'error' when it fails. It stays the same toast: the piece of line that went round becomes the whole line and the time starts.

Each toast is read once, from two live regions built before any toast: politely for information, at once for the kind error. The focus is never moved to a toast; the key of the setting key, F8, goes to the newest one and back, and Escape dismisses it.

The toast is a block of the page marked data-toast-template, which the script copies for every toast: restyle it like any block, in the Designer or in CSS. Under 480 px the stack is the full width of the foot of the window, above the keyboard, whatever the setting position says.