Skip to content
boing

Guide

Animated toast notifications in React

Most toast libraries fade or slide a box in over a fixed time. Boing moves each toast on a spring, so it squashes as it lands, grows when the content grows and changes shape in place when you update it.

Try it

Why springs

A transition with a fixed duration has to start from a known frame. If a toast changes while it is still moving, the next transition either waits or jumps. A spring only needs a target. It starts from the current size and speed, so a toast that is interrupted keeps moving smoothly toward its new shape.

Width, height and position are springs. Text and buttons are revealed as the springing width reaches them, and new text rolls in with a short CSS transition while the width springs to fit it.

One toast that morphs in place

Call toast.update with the id, or wrap a promise, and the same toast changes type, title and width instead of a new one stacking on top:

TypeScript
import { toast } from 'react-boing';

const id = toast.loading('Saving…');
await save();
toast.update(id, { type: 'success', title: 'Saved' });

// or
toast.promise(save(), { loading: 'Saving…', success: 'Saved', error: 'Failed' });

More on progress and results: loading toast.

Tune the springs

There are three motions: enter, morph and stack. Each takes a stiffness and damping. The defaults are enter 320/26, morph 340/27 and stack 400/36. Leave one out to keep its default.

TypeScript
toast.configure({
  springs: {
    enter: { stiffness: 220, damping: 14 }, // bouncier landing
    morph: { stiffness: 420, damping: 32 }, // quicker, calmer reshape
  },
});

New settings apply to toasts shown afterwards. To compare settings live, use the playground.

Use the same spring elsewhere

springEasing turns a spring into a CSS linear() easing and a duration, so other parts of your UI can move the same way:

TypeScript
import { springEasing } from 'react-boing';

const { easing, duration } = springEasing({ stiffness: 320, damping: 11 });
el.animate([{ scale: '1.12 0.86' }, { scale: '1 1' }], { duration, easing });

The Boing logo at the top of this page uses exactly that.

Reduced motion

When the system asks for reduced motion, toasts skip the spring, jump to their final size and fade in over 0.2 seconds. Icon animations, the loading spinner and the countdown line are turned off. You don't need to configure anything. See toast accessibility for the rest of the accessibility behaviour.

Frequently asked questions

Why springs instead of CSS transitions with a fixed duration?

A spring has no fixed duration. When a toast changes mid-animation, the spring starts from where it is and how fast it is moving, so there is no jump back to a start frame.

Can I make the toasts bouncier or calmer?

Yes. Pass springs to toast.configure with a stiffness and damping for enter, morph or stack. Lower damping bounces more, higher stiffness moves faster.

What happens with prefers-reduced-motion?

Toasts skip the spring, jump to their final size and fade in briefly. Icon animations, the countdown line and the loading spinner are turned off.

Do I need an animation library?

No. Boing has no dependencies. The springs are solved in the library and played with the Web Animations API and CSS.