# shadcn/ui toast: use Boing in a shadcn project

To use Boing as the toast in a shadcn/ui app, render its `<Toaster />` in your layout and point its `--boing-*` CSS variables at your shadcn theme tokens. The toasts then use your colours, radius and font in light and dark mode.

## Install and render the Toaster

```bash
npm install react-boing
```

Boing is a regular npm package, not a component copied into your repo, so there is no `components/ui` file to add. Render `<Toaster />` in the root layout as in the [Next.js guide](https://boing.aayushbharti.in/nextjs-toast/), then call `toast.success(…)` from client components.

## Match the shadcn theme with CSS variables

shadcn/ui keeps its palette in CSS variables such as `--popover`, `--border` and `--radius`. Point Boing’s variables at them in your global stylesheet:

```css
/* Outside any @layer, so it beats Boing's own unlayered styles. */
.boing-viewport {
  --boing-bg: var(--popover);
  --boing-fg: var(--popover-foreground);
  --boing-ring: var(--border);
  --boing-error: var(--destructive);
  --boing-radius: var(--radius);
  font-family: inherit;
}
```

- Keep this rule outside `@layer base` or any other layer. Boing’s stylesheet is not in a layer, and unlayered CSS wins over layered CSS no matter the order.
- Newer shadcn themes store full colours (often `oklch(…)`), so `var(--popover)` works as is. Older themes store bare HSL numbers; wrap those as `hsl(var(--popover))`.
- `font-family: inherit` swaps Boing’s system font stack for the one your app sets on `body`.
- Leave `--boing-radius` out if you prefer the default pill shape.

The full list of variables is in [the docs](https://boing.aayushbharti.in/docs/#styling), and the [playground](https://boing.aayushbharti.in/playground/) shows them live.

## Follow class-based dark mode

With `theme="system"` (the default) the Toaster follows the operating system setting. Most shadcn apps switch themes with a `dark` class from `next-themes` instead, so pass the resolved theme through:

```tsx
'use client';

import { useTheme } from 'next-themes';
import { Toaster } from 'react-boing';

/** Boing's Toaster with its theme taken from next-themes, so toasts follow the app's dark class. */
export function AppToaster() {
  const { resolvedTheme } = useTheme();
  const theme = resolvedTheme === 'dark' || resolvedTheme === 'light' ? resolvedTheme : 'system';
  return <Toaster theme={theme} />;
}
```

Render `<AppToaster />` inside your `ThemeProvider`. The variables mapped above already change with the `dark` class; the `theme` prop makes the parts you did not map, such as the status icon colours, switch with them.

## When to keep the shadcn Sonner toast

The toast that shadcn/ui installs today is a themed wrapper around Sonner. It is a good default, and switching is not always worth it. Keep it when:

- You want several toasts stacked on screen at once as the normal behaviour.
- You render custom JSX inside toasts. Boing shows text, an optional image, a progress bar and up to two buttons.
- The toast already looks the way you want and nobody has asked for a change.

Boing fits better when you want one toast that changes in place, spring motion, an undo button that morphs into a confirmation, or built-in sounds. The [Sonner comparison](https://boing.aayushbharti.in/sonner-alternative/) goes through the differences call by call.

## Frequently asked questions

### Is there a shadcn registry item for Boing?

No. Boing installs from npm as `react-boing` and is styled with CSS variables, so there is no component file to copy in.

### Can I run Boing and the shadcn Sonner toaster side by side?

They do not conflict, since each has its own Toaster and its own `toast` import. Two toast systems on one screen is confusing for users, though, so it is best kept to a migration period.

### Why does my CSS override not apply?

Check that the rule is not inside an `@layer` block. Boing adds its styles without a layer, and unlayered rules always beat layered ones.

### How do I make toasts follow the dark class from next-themes?

Read `resolvedTheme` from `useTheme()` in a small client component and pass it to the Toaster `theme` prop.

## Related guides

- [Next.js toast notifications in the App Router (Boing)](https://boing.aayushbharti.in/nextjs-toast/): Toasts in a server-first app.
- [Sonner alternative that shows one toast at a time](https://boing.aayushbharti.in/sonner-alternative/): One toast that morphs instead of a stack.
- [Toast playground](https://boing.aayushbharti.in/playground/): Pick a style, tweak it, copy the code.
- [Boing docs](https://boing.aayushbharti.in/docs/): Setup, options, styling, sound and accessibility.

Source: https://boing.aayushbharti.in/shadcn-toast/
