SolutionsCase StudiesAI ToolsResourcesAboutContact
Get Your Free AI Automation Audit Book a Free 30-Minute Strategy Call
Playground~/frontend Open editor

~/css/alerts-banners

7 CSS Banners and Alerts

4 Pure CSS3 with JSPublished 2026-10-05Free · no sign-up

Seven message components: info, success, warning and error alerts, an announcement that stays dismissed, a site-wide maintenance banner, a deletion alert with Undo, documentation callouts, a confirmation that dismisses itself unless you hover it and an error with expandable technical details.

01. Info, Success, Warning and Error

AlertStatus

The four alert levels, each with an icon, a bold label and the message. The label (Success, Warning) is real text, so the level does not depend on colour, and only the error uses role="alert", because interrupting someone is for problems, not good news.

View code
<div class="al1"><p class="i"><span aria-hidden="true">ℹ</span><b>Note:</b> Prices include VAT.</p><p class="s" role="status"><span aria-hidden="true">✓</span><b>Success:</b> Your changes are saved.</p><p class="w"><span aria-hidden="true">!</span><b>Warning:</b> Your trial ends in 3 days.</p><p class="e" role="alert"><span aria-hidden="true">✕</span><b>Error:</b> The card was declined.</p></div>
.al1 { display: grid; gap: 8px; width: 340px; max-width: 100%; font: 14px Inter, system-ui, sans-serif; }
.al1 p { display: flex; align-items: baseline; gap: 8px; margin: 0; padding: 10px 12px; border: 1px solid; border-radius: 10px; }
.al1 span { flex: none; display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; color: #fff; font-size: 12px; font-weight: 800; transform: translateY(3px); }
.al1 .i { border-color: #b2ddff; background: #eff8ff; color: #194185; } .al1 .i span { background: #1570ef; }
.al1 .s { border-color: #abefc6; background: #ecfdf3; color: #054f31; } .al1 .s span { background: #079455; }
.al1 .w { border-color: #fedf89; background: #fffaeb; color: #7a2e0e; } .al1 .w span { background: #b54708; }
.al1 .e { border-color: #fecdca; background: #fef3f2; color: #7a271a; } .al1 .e span { background: #d92d20; }

02. Dismissible Alert That Stays Dismissed

AlertDismiss

An announcement with a close button that remembers it was dismissed for the rest of the visit through sessionStorage, so it does not reappear on every page. The close button names the alert it closes, and focus moves to the next sensible place.

View code
<div class="al2"><div class="msg" role="region" aria-label="Announcement"><p>New: export your reports to PDF.</p><button aria-label="Dismiss announcement">&times;</button></div><a href="#reports" class="next">Go to reports</a></div>
.al2 { display: grid; gap: 12px; width: 340px; max-width: 100%; font: 14px Inter, system-ui, sans-serif; }
.al2 .msg { display: flex; align-items: center; gap: 10px; padding: 10px 8px 10px 14px; border-radius: 10px; background: #1e2546; color: #e0e7ff; }
.al2 p { flex: 1; margin: 0; }
.al2 button { width: 30px; height: 30px; border: 0; border-radius: 8px; background: transparent; color: #c7d2fe; font-size: 20px; cursor: pointer; }
.al2 .next { color: #a5b4fc; }
.al2 :focus-visible { outline: 2px solid #a5b4fc; outline-offset: 2px; }
var m = document.querySelector('.al2 .msg'), key = 'al2-dismissed';
try { if (sessionStorage.getItem(key)) m.remove(); } catch (e) {}
var b = document.querySelector('.al2 button');
if (b) b.onclick = function () { try { sessionStorage.setItem(key, '1'); } catch (e) {} m.remove(); document.querySelector('.al2 .next').focus(); };

03. Site-Wide Maintenance Banner

BannerNotice

A full-width banner at the top of every page for planned maintenance, with the time window in a time element and a link to the status page. It is a region with a label, so screen reader users can find or skip it like any landmark.

View code
<div class="al3" role="region" aria-label="Service notice"><p><b>Planned maintenance</b> on <time datetime="2026-10-12T02:00Z">12 Oct, 02:00-03:00 UTC</time>. Checkout may be unavailable. <a href="#status">Status page</a></p></div>
.al3 { width: 100%; padding: 10px 16px; box-sizing: border-box; background: #fef0c7; border-bottom: 1px solid #fedf89; color: #7a2e0e; font: 14px/1.5 Inter, system-ui, sans-serif; text-align: center; }
.al3 p { margin: 0; } .al3 b { color: #4e1d09; } .al3 a { color: #4e1d09; font-weight: 600; }
.al3 a:focus-visible { outline: 2px solid #4e1d09; outline-offset: 2px; }

04. Alert with an Undo Action

AlertAction

After deleting something, an alert confirms it and offers Undo, which is kinder than an Are you sure dialog. The message is a polite live region, the Undo button restores the item, and the alert removes itself after ten seconds.

View code
<div class="al4"><ul><li id="al4i">Draft: Autumn newsletter <button class="del">Delete</button></li></ul><div class="bar" role="status"></div></div>
.al4 { width: 340px; max-width: 100%; font: 14px Inter, system-ui, sans-serif; }
.al4 ul { margin: 0 0 10px; padding: 0; list-style: none; }
.al4 li { display: flex; justify-content: space-between; align-items: center; padding: 12px; border-radius: 10px; background: #1e293b; color: #e2e8f0; }
.al4 .del { padding: 6px 10px; border: 1px solid #f87171; border-radius: 6px; background: transparent; color: #fca5a5; font: 600 13px Inter, system-ui, sans-serif; cursor: pointer; }
.al4 .bar:not(:empty) { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; border-radius: 10px; background: #f8fafc; color: #0f172a; }
.al4 .bar button { padding: 6px 10px; border: 0; border-radius: 6px; background: #0f172a; color: #fff; font: 700 13px Inter, system-ui, sans-serif; cursor: pointer; }
.al4 :focus-visible { outline: 2px solid #93c5fd; outline-offset: 2px; }
var ul = document.querySelector('.al4 ul'), bar = document.querySelector('.al4 .bar'), saved, t;
ul.addEventListener('click', function (e) { if (!e.target.classList.contains('del')) return; saved = e.target.parentNode; saved.remove();
  bar.innerHTML = '<span>Draft deleted.</span><button type="button">Undo</button>'; var u = bar.querySelector('button'); u.focus();
  u.onclick = function () { ul.appendChild(saved); bar.innerHTML = ''; clearTimeout(t); saved.querySelector('.del').focus(); };
  clearTimeout(t); t = setTimeout(function () { bar.innerHTML = ''; }, 10000); });

05. Documentation Callouts

AlertDocs

Note, Tip and Caution boxes for documentation, with a coloured left border, a label and the text. They are asides with a label heading rather than alerts, because they are part of the content, not something that just happened.

View code
<div class="al5"><aside class="note" aria-label="Note"><b>Note</b><p>The API returns dates in UTC.</p></aside><aside class="tip" aria-label="Tip"><b>Tip</b><p>Cache responses for up to 5 minutes.</p></aside><aside class="warn" aria-label="Caution"><b>Caution</b><p>Deleting a key cannot be undone.</p></aside></div>
.al5 { display: grid; gap: 10px; width: 340px; max-width: 100%; font: 14px/1.5 Inter, system-ui, sans-serif; }
.al5 aside { padding: 10px 14px; border-left: 4px solid; border-radius: 4px 10px 10px 4px; }
.al5 b { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; } .al5 p { margin: 2px 0 0; color: #344054; }
.al5 .note { border-color: #1570ef; background: #eff8ff; } .al5 .note b { color: #175cd3; }
.al5 .tip { border-color: #079455; background: #ecfdf3; } .al5 .tip b { color: #067647; }
.al5 .warn { border-color: #dc6803; background: #fffaeb; } .al5 .warn b { color: #b54708; }

06. Auto-Dismiss with Pause on Hover

AlertTimer

A confirmation that closes itself after six seconds, with a bar showing the time left. Hovering or focusing it pauses the timer through animation-play-state, which gives people time to read, and the alert is closed when its bar's animation ends.

View code
<div class="al6"><button class="show">Save settings</button><div class="zone" role="status"></div></div>
.al6 { width: 320px; max-width: 100%; font: 14px Inter, system-ui, sans-serif; }
.al6 .show { margin-bottom: 10px; padding: 9px 14px; border: 0; border-radius: 8px; background: #e2e8f0; color: #0f172a; font: 700 14px Inter, system-ui, sans-serif; cursor: pointer; }
.al6 .box { position: relative; overflow: hidden; padding: 12px 14px 16px; border-radius: 10px; background: #052e16; color: #bbf7d0; }
.al6 .box i { position: absolute; left: 0; bottom: 0; height: 4px; width: 100%; background: #22c55e; transform-origin: left; animation: al6 6s linear forwards; }
.al6 .box:hover i, .al6 .box:focus-within i { animation-play-state: paused; }
.al6 .box button { margin-left: 8px; padding: 2px 8px; border: 1px solid #4ade80; border-radius: 6px; background: transparent; color: #bbf7d0; font: 600 12px Inter, system-ui, sans-serif; cursor: pointer; }
@keyframes al6 { to { transform: scaleX(0); } }
.al6 :focus-visible { outline: 2px solid #86efac; outline-offset: 2px; }
var zone = document.querySelector('.al6 .zone');
document.querySelector('.al6 .show').onclick = function () {
  zone.innerHTML = '<div class="box">Settings saved.<button type="button">Close</button><i aria-hidden="true"></i></div>';
  var box = zone.firstChild; box.querySelector('i').addEventListener('animationend', function () { box.remove(); }); box.querySelector('button').onclick = function () { box.remove(); };
};

07. Alert with Expandable Details

AlertDisclosure

An error alert that gives a short message first and technical details behind a Show details toggle, so people are not overwhelmed but support staff still get what they need. The details use the native details element and include a copyable error code.

View code
<div class="al7" role="alert"><p><b>Payment failed.</b> Your bank declined the charge. Try another card.</p><details><summary>Show details</summary><p>Error code: <code>card_declined/insufficient_funds</code><br>Reference: 7F3A-21C9</p></details></div>
.al7 { width: 340px; max-width: 100%; box-sizing: border-box; padding: 12px 14px; border: 1px solid #fecdca; border-radius: 10px; background: #fef3f2; color: #7a271a; font: 14px/1.5 Inter, system-ui, sans-serif; }
.al7 p { margin: 0; }
.al7 summary { margin-top: 6px; color: #b42318; font-weight: 600; cursor: pointer; }
.al7 details p { margin-top: 6px; color: #912018; font-size: 13px; }
.al7 code { font: 12px "JetBrains Mono", ui-monospace, monospace; overflow-wrap: anywhere; }
.al7 summary:focus-visible { outline: 2px solid #b42318; outline-offset: 2px; border-radius: 4px; }

About these CSS Banners and Alerts

Choose the right role

Use role="alert" only for errors and urgent problems, because it interrupts. Confirmations belong in role="status", and static content such as documentation callouts needs no live role at all.

Say the level in words

Start the message with Success, Warning or Error in text. Colour and icons help sighted people scan, but the word works for everyone, including people who cannot tell red from green.

Undo beats confirm

For reversible actions, act immediately and offer Undo, rather than asking Are you sure first. Keep the Undo available long enough to use, around ten seconds.

Self-closing messages wait for readers

If a message closes itself, pause the timer while it is hovered or focused, and never put anything essential in a message that disappears.

Frequently asked questions

Where should page-level banners go?

At the very top, before the header, as a labelled region.

Does the dismissed banner come back?

Not for the rest of the visit; it uses sessionStorage, which clears when the tab closes.

Should errors include codes?

Give a plain explanation first and put codes behind a details toggle for support.