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.
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:
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.
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:
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.
Related guides
- React toast notificationsOne component and one function call.
- Loading toastOne toast from loading to done.
- Undo toastAct first, offer undo.
- Accessible toast notificationsToasts screen readers and keyboards can use.
- Boing docsSetup, options, styling, sound and accessibility.
- Toast playgroundPick a style, tweak it, copy the code.