Alert banner
Also called alert, notification banner, or callout
A colored strip in the page that delivers an important message, such as info, success, warning, or error, and stays until it is resolved or dismissed.
import { useState, type ReactNode } from 'react';
import { AnimatePresence, motion } from 'motion/react';
const TONES = {
info: 'border-blue-500/40 bg-blue-500/10 text-blue-600',
success: 'border-green-500/40 bg-green-500/10 text-green-600',
warning: 'border-amber-500/40 bg-amber-500/10 text-amber-600',
error: 'border-red-500/40 bg-red-500/10 text-red-600'
};
type Props = { tone: keyof typeof TONES; children: ReactNode };
// <AlertBanner tone='warning'>Your trial ends in 3 days. <a href='/billing'>Add a card</a></AlertBanner>
export function AlertBanner({ tone, children }: Props) {
const [open, setOpen] = useState(true);
return (
<AnimatePresence>
{open && (
// Animating height pushes the page down (and back up) instead of jumping.
<motion.div
initial={{ height: 0, opacity: 0 }}
animate={{ height: 'auto', opacity: 1 }}
exit={{ height: 0, opacity: 0 }}
transition={{ duration: 0.2, ease: [0.23, 1, 0.32, 1] }}
className='overflow-hidden'
>
{/* Errors interrupt screen readers right away; the rest wait their turn. */}
<div
role={tone === 'error' ? 'alert' : 'status'}
className={`mb-4 flex items-center gap-3 rounded-lg border px-4 py-3 text-sm ${TONES[tone]}`}
>
<svg
viewBox='0 0 16 16'
aria-hidden='true'
className='size-4 shrink-0 fill-none stroke-current stroke-[1.5]'
>
<circle cx='8' cy='8' r='6.5' />
<path d='M8 5v3.5M8 11h.01' />
</svg>
<p className='flex-1 text-foreground'>{children}</p>
<button
aria-label='Dismiss'
onClick={() => setOpen(false)}
className='opacity-60 hover:opacity-100'
>
✕
</button>
</div>
</motion.div>
)}
</AnimatePresence>
);
}Add an alert banner component with four variants (info in blue, success in green, warning in amber, error in red), each with an icon, a one-line message, an optional action link, and a close button. It appears at the top of the page by expanding its height and fading in over 200ms, and collapses the same way when dismissed so the content below moves smoothly. Use role="alert" for errors and role="status" for the rest.
Paste into Layerwise or any AI coding tool.
What is Alert banner?
An alert banner is a full-width box with an icon, a short message, and often an action or a close button. Its color matches the tone: blue for info, green for success, amber for warnings, and red for errors. It sits in the page layout, usually at the top of the page or a section, and pushes the content below it down.
Use it for messages that apply to the whole page and should stay visible until handled: a failed payment, scheduled maintenance, a trial that ends in three days, an error that blocks saving. For a quick confirmation such as “Saved”, use a toast, which disappears on its own.
Keep it to one sentence plus an action, and show one banner at a time where you can, since a stack of them reads as noise. Use role="alert" for urgent errors so screen readers announce them right away, and role="status" for calmer updates.
Often confused with
- Toast notification
- A toast floats over the page for a few seconds and disappears on its own. An alert banner sits in the layout and stays until the issue is fixed or someone dismisses it.
- Modal
- A modal blocks the page until you respond. An alert banner informs you while you keep working.
Related terms
All termsToast notification
A brief message that slides into a corner of the screen to confirm an action, then disappears on its own after a few seconds.
Modal
A window that opens over the page, dims everything behind it, and blocks the rest of the interface until you finish or dismiss it.
Height auto animation
An animation that opens or closes a panel to the exact height of its content, even though that height is unknown ahead of time.
Inline validation
Form checking that happens right next to each field as you fill it in, showing an error or a checkmark before you press Submit.
Build it with Layerwise
Describe your app, watch it run in a live preview, and publish it with a database, storage, and sign-in built in.