shadcn.io is not affiliated with official shadcn/ui
Sonner examples · Standard
Default Toast Sonner for React
A button that shows a plain toast with one line of text.
A plain toast says that something happened, with no success or error icon. The button calls toast with one string, and Toaster shows it for 4 seconds. Use it for neutral notices: a record created, a setting changed, a link copied.
Preview
Installation
FAQ
What does this toast call pass?
The button calls toast with "Event has been created" and no second argument. There is no description, action, or icon on this call, so the notice is that one line.
Does the demo render the toaster?
The demo renders its own Toaster beside the button, so it works on its own. In an app, render one Toaster near the root and call toast from anywhere.
How do I get a success or error icon on this message?
Call toast.success, toast.error, toast.warning, or toast.info with the message. Each helper sets a type, and Toaster draws the matching icon. This demo stays on plain toast, which leaves the icon slot empty.
How do I add a second line under the title?
Pass description in the second argument. That string renders under the title. This call does not pass it.
Where does this toast show up?
This call does not pass position. Toaster uses bottom-right when that prop is omitted. Set position on Toaster when every toast should share another spot.
When is the Toast component a better fit?
Use Sonner for this pattern: one toast() call and a single Toaster. Use Toast when the notice should be built from the same parts as the rest of the page. Sonner itself is React only.
Related
- Success Toast SonnerA button that shows a success toast with
- Error Toast SonnerA button that shows an error toast with
- Warning Toast SonnerA button that shows a warning toast with
- Info Toast SonnerA button that shows an info toast with
- Toast with Action Button SonnerA toast with an Undo action button that
- Standard with Title AlertA neutral alert with only a title, for a