Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Sonner examples · Position

Top Center Position Sonner for React

A button that shows a toast in the top center of the screen.

Framework
UI library

Top center is where people look first, so keep it for notices they mustn't miss. This toast passes position: "top-center" on the call, so only this toast moves there.

Preview

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

FAQ

Where does this toast appear?

The button calls toast("This is a toast", { position: "top-center" }). That places this notice at the top center. Other toasts keep the position set on Toaster.

How do I put every toast in that spot?

Set position="top-center" on Toaster. This demo sets position on the one call, which is how a single notice lands somewhere the others do not.

Does the position change the message?

No. The message is the string "This is a toast". This call passes no description, icon, action, or duration.

What if I leave position off the call?

Omit position and Toaster uses bottom-right. This call passes top-center so only this notice moves. The allowed values are top-left, top-center, top-right, bottom-left, bottom-center, and bottom-right.

How do several toasts at this position stack?

Toasts along the top stack downward from that edge. This file only fires one toast, with that position on the call.

Does the demo render the toaster?

Yes. The demo renders its own Toaster beside the button, with no position of its own. In an app, render one Toaster near the root; a position on toast moves only that toast.