Skip to main content

Toast Component

Last updated:

CSS-only Tailwind CSS toast for notification positioning: top, bottom, start, end, and center placement. No JavaScript for layout. WCAG AA accessible, works with Django, HTMX, Laravel, React, and any stack.

Toast components display brief, non-intrusive notifications positioned at the edges of the screen. Built with fixed positioning and alert components, toasts communicate system feedback like success confirmations, error messages, or status updates. The Frutjam toast system supports six placement positions, ideal for form submissions, async operations, and real-time notifications.

CSS-only, no JavaScript required. WCAG AA accessible and framework-agnostic: works with Django, HTMX, Laravel, React, and any stack.

ClassTypeDescription
toastBaseFixed-position notification container
toast-topModifierAnchors to the top of the viewport
toast-bottomModifierAnchors to the bottom of the viewport (default)
toast-startModifierAnchors to the left
toast-centerModifierHorizontally centered
toast-endModifierAnchors to the right (default)
toast-middleModifierVertically centered
toast-slide-upModifierEnters from below, by its own height
toast-slide-downModifierEnters from above
toast-slide-startModifierEnters from the left, from the right in RTL
toast-slide-endModifierEnters from the right, from the left in RTL
--toast--widthSizeMaximum width of each toast, 24rem by default

Basic Usage

New message arrived.
1
2
3
4
5
<div role="status" aria-live="polite" class="toast">
  <div class="alert alert-info">
    <span>New message arrived.</span>
  </div>
</div>
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
import { useToast } from 'frutjam/react'

export default function ToastDemo() {
  const toast = useToast()
  return (
    <>
      <button className="btn" onClick={() => toast.info('New message arrived.')}>Show Toast</button>
      <div role="status" aria-live="polite" className="toast">
        {toast.toasts.map(t => (
          <div key={t.id} className={`alert${t.type ? ` alert-${t.type}` : ''}`}>
            <span>{t.message}</span>
          </div>
        ))}
      </div>
    </>
  )
}

Toast Positions

Top Positions

Top Start
Top Center
Top End
html
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
<div role="status" aria-live="polite" class="toast toast-top toast-start">
  <div class="alert alert-info"><span>Top Start</span></div>
</div>

<div role="status" aria-live="polite" class="toast toast-top toast-center">
  <div class="alert alert-info"><span>Top Center</span></div>
</div>

<div role="status" aria-live="polite" class="toast toast-top toast-end">
  <div class="alert alert-info"><span>Top End</span></div>
</div>

Bottom Positions

Bottom Start
Bottom Center
Bottom End
html
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
<div role="status" aria-live="polite" class="toast toast-bottom toast-start">
  <div class="alert alert-info"><span>Bottom Start</span></div>
</div>

<div role="status" aria-live="polite" class="toast toast-bottom toast-center">
  <div class="alert alert-info"><span>Bottom Center</span></div>
</div>

<div role="status" aria-live="polite" class="toast toast-bottom toast-end">
  <div class="alert alert-info"><span>Bottom End</span></div>
</div>

Centered

A horizontal and a vertical modifier combine, so toast-center toast-middle puts a toast in the middle of the screen.

Middle Center
html
1
2
3
<div role="status" aria-live="polite" class="toast toast-middle toast-center">
  <div class="alert alert-info"><span>Middle Center</span></div>
</div>

Entry Animation

Every toast fades and rises into place on its own. There is nothing to add for that, and no class to turn it on.

The toast-slide-* modifiers are for when you want a different direction from the default rise. Pick the edge the toast sits on, so it enters from outside the screen rather than across it: toast-slide-end belongs with toast-end, toast-slide-down with toast-top.

Drops in from the top
html
1
2
3
<div role="status" aria-live="polite" class="toast toast-top toast-end toast-slide-down">
  <div class="alert alert-info"><span>Drops in from the top</span></div>
</div>

The distance is the toast's own width or height, not the distance to the edge of the screen, so a centered toast starts near the middle rather than off-screen.

There is no exit animation. A toast disappears the moment it is removed from the page, because CSS has no state to transition out of. Fading one out means keeping it in the DOM and animating it yourself.

The animation is skipped for anyone who has asked for reduced motion.

Width

Each toast is capped at 24rem so a long message does not span a phone screen. Override --toast--width to change it.

html
1
2
3
<div role="status" aria-live="polite" class="toast [--toast--width:32rem]">
  <div class="alert alert-info"><span>A wider toast.</span></div>
</div>

Toast Colors

File saved successfully.
Storage is almost full.
Connection failed.
Update available.
html
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
<div role="status" aria-live="polite" class="toast toast-top toast-end">
  <div class="alert alert-success">
    <span>File saved successfully.</span>
  </div>
  <div class="alert alert-warning">
    <span>Storage is almost full.</span>
  </div>
  <div class="alert alert-error">
    <span>Connection failed.</span>
  </div>
  <div class="alert alert-info">
    <span>Update available.</span>
  </div>
</div>

Multiple Toasts

Profile updated.
2 new notifications.
html
1
2
3
4
5
6
7
8
<div role="status" aria-live="polite" class="toast toast-top toast-end">
  <div class="alert alert-success">
    <span>Profile updated.</span>
  </div>
  <div class="alert alert-info">
    <span>2 new notifications.</span>
  </div>
</div>

Using Claude Code, Cursor, or another AI editor?

Cherry MCP gives your AI editor the exact Toast class names and structure on demand. No more hallucinated classes.

Try Cherry MCP

Found this useful?

Star Frutjam on GitHub. It's how other developers discover it.