Alert Banner

Dismissible alert banner in 4 variants.

✓

Success. Your profile has been updated.

!

Warning. Your trial ends in 3 days.

×

Error. Payment failed. Try again.

i

Info. New features are available.

Tailwind CSS
<div class="w-full max-w-lg space-y-3">
  <div class="flex items-start gap-3 rounded-2xl border border-emerald-200 bg-emerald-50 px-4 py-3">
    <span class="text-emerald-600 font-bold">✓</span>
    <p class="text-sm text-emerald-800"><span class="font-bold">Success.</span> Your profile has been updated.</p>
  </div>
  <div class="flex items-start gap-3 rounded-2xl border border-amber-200 bg-amber-50 px-4 py-3">
    <span class="text-amber-600 font-bold">!</span>
    <p class="text-sm text-amber-800"><span class="font-bold">Warning.</span> Your trial ends in 3 days.</p>
  </div>
  <div class="flex items-start gap-3 rounded-2xl border border-red-200 bg-red-50 px-4 py-3">
    <span class="text-red-600 font-bold">×</span>
    <p class="text-sm text-red-800"><span class="font-bold">Error.</span> Payment failed. Try again.</p>
  </div>
  <div class="flex items-start gap-3 rounded-2xl border border-blue-200 bg-blue-50 px-4 py-3">
    <span class="text-blue-600 font-bold">i</span>
    <p class="text-sm text-blue-800"><span class="font-bold">Info.</span> New features are available.</p>
  </div>
</div>

Free to use in personal and commercial projects. No attribution required.

Variants

Same component, different looks. Preview each one live and copy the code you like.

Solid

Solid banners command attention for critical system messages.

✓

Success. Your profile has been updated.

×

Error. Payment failed. Try again.

Tailwind CSS

Dark

Dark banners blend into dark dashboards without shouting.

✓

Success. Your profile has been updated.

!

Warning. Your trial ends in 3 days.

Tailwind CSS

Dismissible

Add dismiss buttons to banners the user has already acknowledged.

!

Warning. Your trial ends in 3 days.

i

Info. New features are available.

Tailwind CSS

About this alert banner

Alert banners are the in-page alternative to toasts: they sit in the layout and stay until dismissed. This css alert banner set covers the four semantic variants every design system needs: success (emerald), warning (amber), error (red), and info (blue). The color system is instant to parse because it matches real-world conventions.

Each alert pairs a tinted background (emerald-50) with a darker border (emerald-200) and text (emerald-800). This three-level color scale keeps alerts readable without shouting. The bold lead word ("Success.") lets scanners get the gist without reading the sentence.

Place alerts where the action happened: above a form for validation errors, at the top of settings for plan notices. One alert at a time; if you need more, something is wrong with the page, not the alerts.

Some messages must live in the page rather than float above it: a failed save, an expiring trial, a maintenance window. Toasts vanish and modals interrupt; banners persist in the layout, right where the user's eyes already are. They trade interruption for permanence, which is the right trade when the message outlasts the moment.

Each banner is flex items-start gap-3 rounded-2xl with a three-level color scale: bg-emerald-50 for the background, border-emerald-200 for the edge, text-emerald-800 for the copy. The icon glyph in text-emerald-600 reinforces the severity for color-blind users. A bold lead word up front means scanners grasp the message in two words and move on. Four variants cover the semantics every system needs: emerald, amber, red, blue.

Give informational banners a dismiss button; keep error banners persistent until resolved. Place validation banners directly above the form they describe, not at the page top. In dark mode, flip the scale to dark tinted backgrounds with light text rather than reusing the light palette, which glares.

The visual mistake is the accent-border style: coloring only a thin left stripe while the rest of the banner stays gray. Testing consistently shows users scan past these because the banner doesn't read as a colored unit. Tint the full background at the 50 level; the whole banner should carry the severity, not just a stripe.

Where to use it

  • ✓ Form validation messages
  • ✓ Plan and billing notices
  • ✓ System status updates
  • ✓ Onboarding hints

Customization tips

Add a dismiss button for non-critical alerts. For critical errors, keep them persistent until resolved. Use role="alert" for screen readers on dynamic alerts.

Design notes

When to use

Alert banners suit page-level messages the user should notice but does not need to act on immediately, like a successful save or a scheduled maintenance notice. The four color variants let the severity read at a glance: green confirms, red warns, and the icon reinforces the message for color-blind users. The dismiss button keeps the banner from becoming permanent clutter once its job is done.

What to avoid

Do not stack three banners at once, users will dismiss all of them without reading any. Avoid using a banner for errors tied to a specific form field, those belong inline next to the field where the fix happens. And do not auto-dismiss error banners, a message that vanishes before it is read might as well never have appeared.

Accessibility

Error and warning banners should use role alert so screen readers announce them when they appear. Do not rely on color alone, the icon and the heading text must carry the meaning too.

Frequently asked questions

Alert banner vs toast, which should I use?

Alerts sit in the page layout and persist; use for important messages tied to a location (form errors). Toasts float and auto-dismiss; use for transient confirmations.

What colors should alerts use?

Emerald/green for success, amber/yellow for warning, red for error, blue for info. These mappings are universal; do not invent your own.

Should alerts be dismissible?

Informational alerts, yes. Error alerts tied to unresolved problems should stay until fixed. Success alerts can auto-dismiss after a few seconds.

Should alert banners use role="alert"?

Use role="alert" only for important, time-sensitive messages like errors, because screen readers announce it immediately and interrupt the user. For neutral info banners, use role="status" or no live region at all. Overusing role alert trains users to ignore announcements.

How do I auto-dismiss an alert banner?

Use setTimeout to fade the banner out after 5 to 8 seconds, but only for low-stakes confirmations like "Settings saved". Errors and warnings should stay until dismissed manually so the user does not miss them. Pause the timer while the banner is hovered or focused.

How do I add icons to alert banners?

Place an inline SVG icon before the message, one per severity: check circle for success, info circle for info, warning triangle for warning, octagon for error. Mark icons aria-hidden="true" since the text already carries the meaning. Align icon and text with flex and a small gap.