Skip to the main content

Alert Banners

Free Feedback

Information, success, warning and error banners with an icon, a heading, a dismiss button and the right live-region role for each kind.

Checked on 3 December 2026 in Chrome 143.0.7499.169: 12 automated checks. What the checks are

Preview and code

HTML

<section class="alb" aria-labelledby="alb-title">
  <h2 class="alb__title" id="alb-title">Alert banners</h2>

  <div class="alb__stack" id="alb-stack">
    <div class="alb__banner alb__banner--info" role="status">
      <svg class="alb__icon" viewBox="0 0 24 24" width="24" height="24" aria-hidden="true" focusable="false"><circle cx="12" cy="12" r="10" fill="none" stroke="currentColor" stroke-width="2"/><path d="M12 11v6" stroke="currentColor" stroke-width="2.2" stroke-linecap="round"/><circle cx="12" cy="7.5" r="1.3" fill="currentColor"/></svg>
      <div class="alb__body">
        <p class="alb__heading">Information</p>
        <p class="alb__text">A new version of the example guide is ready to read.</p>
      </div>
      <button class="alb__dismiss" type="button" aria-label="Dismiss information message"><svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true" focusable="false"><path d="m3 3 10 10M13 3 3 13" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg></button>
    </div>

    <div class="alb__banner alb__banner--success" role="status">
      <svg class="alb__icon" viewBox="0 0 24 24" width="24" height="24" aria-hidden="true" focusable="false"><circle cx="12" cy="12" r="10" fill="none" stroke="currentColor" stroke-width="2"/><path d="m7.5 12.5 3 3 6-6.5" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"/></svg>
      <div class="alb__body">
        <p class="alb__heading">Saved</p>
        <p class="alb__text">Your changes to the sample page were saved.</p>
      </div>
      <button class="alb__dismiss" type="button" aria-label="Dismiss success message"><svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true" focusable="false"><path d="m3 3 10 10M13 3 3 13" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg></button>
    </div>

    <div class="alb__banner alb__banner--warning" role="alert">
      <svg class="alb__icon" viewBox="0 0 24 24" width="24" height="24" aria-hidden="true" focusable="false"><path d="M12 3 22 20H2Z" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/><path d="M12 10v5" stroke="currentColor" stroke-width="2.2" stroke-linecap="round"/><circle cx="12" cy="17.6" r="1.2" fill="currentColor"/></svg>
      <div class="alb__body">
        <p class="alb__heading">Check before you go on</p>
        <p class="alb__text">Two sample fields are empty. You can still continue.</p>
      </div>
      <button class="alb__dismiss" type="button" aria-label="Dismiss warning message"><svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true" focusable="false"><path d="m3 3 10 10M13 3 3 13" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg></button>
    </div>

    <div class="alb__banner alb__banner--error" role="alert">
      <svg class="alb__icon" viewBox="0 0 24 24" width="24" height="24" aria-hidden="true" focusable="false"><path d="M8.3 2.5h7.4l5.8 5.8v7.4l-5.8 5.8H8.3l-5.8-5.8V8.3Z" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/><path d="m9 9 6 6m0-6-6 6" stroke="currentColor" stroke-width="2.2" stroke-linecap="round"/></svg>
      <div class="alb__body">
        <p class="alb__heading">Problem</p>
        <p class="alb__text">The sample upload stopped. Try the file again.</p>
      </div>
      <button class="alb__dismiss" type="button" aria-label="Dismiss error message"><svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true" focusable="false"><path d="m3 3 10 10M13 3 3 13" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg></button>
    </div>
  </div>

  <p class="alb__empty" id="alb-empty" hidden>
    <span>All messages dismissed.</span>
    <button class="alb__restore" type="button" id="alb-restore">Show them again</button>
  </p>
</section>

CSS

.alb {
  --alb-bg: #ffffff;
  --alb-ink: #1c2033;
  --alb-muted: #4b5266;
  --alb-line: #d5d9e6;
  --alb-focus: #1c2033;
  /* each kind: tint, bar and icon colour, text colour */
  --alb-info-bg: #eaf1ff;      --alb-info-bar: #1d4ed8;      --alb-info-ink: #14275c;
  --alb-success-bg: #e6f6ec;   --alb-success-bar: #15803d;   --alb-success-ink: #0f3d22;
  --alb-warning-bg: #fff4d6;   --alb-warning-bar: #a15c00;   --alb-warning-ink: #4a2c00;
  --alb-error-bg: #fdeceb;     --alb-error-bar: #b3261e;     --alb-error-ink: #5c1410;
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  max-width: 36rem;
  color: var(--alb-ink);
}
.alb *, .alb *::before, .alb *::after { box-sizing: inherit; }
.alb__title { margin: 0 0 0.7rem; font-size: 1.25rem; line-height: 1.2; letter-spacing: -0.01em; }
.alb__stack { display: grid; gap: 0.55rem; }

.alb__banner {
  --alb-bg: var(--alb-info-bg); --alb-bar: var(--alb-info-bar); --alb-fg: var(--alb-info-ink);
  display: flex; align-items: flex-start; gap: 0.8rem;
  padding: 0.75rem 0.9rem 0.75rem 1rem;
  color: var(--alb-fg);
  background: var(--alb-bg);
  border: 1px solid var(--alb-bar);
  border-left-width: 6px;
  border-radius: 12px;
  animation: alb-in 0.25s ease-out;
}
.alb__banner--success { --alb-bg: var(--alb-success-bg); --alb-bar: var(--alb-success-bar); --alb-fg: var(--alb-success-ink); }
.alb__banner--warning { --alb-bg: var(--alb-warning-bg); --alb-bar: var(--alb-warning-bar); --alb-fg: var(--alb-warning-ink); }
.alb__banner--error   { --alb-bg: var(--alb-error-bg);   --alb-bar: var(--alb-error-bar);   --alb-fg: var(--alb-error-ink); }
.alb__icon { flex: none; margin-top: 0.1rem; color: var(--alb-bar); }
.alb__body { flex: 1 1 auto; min-width: 0; }
.alb__heading { margin: 0; font-size: 0.98rem; font-weight: 700; line-height: 1.35; }
.alb__text { margin: 0.1rem 0 0; font-size: 0.92rem; line-height: 1.45; }

.alb__dismiss { display: none; }
.alb--js .alb__dismiss {
  flex: none; display: inline-grid; place-items: center;
  width: 2.5rem; height: 2.5rem; margin: -0.35rem -0.4rem -0.35rem 0;
  color: var(--alb-fg); background: transparent; border: 0; border-radius: 10px; cursor: pointer;
}
.alb--js .alb__dismiss:hover { background: rgba(0, 0, 0, 0.08); }
.alb__dismiss:focus-visible, .alb__restore:focus-visible { outline: 3px solid var(--alb-focus); outline-offset: 2px; }

.alb__empty {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.6rem;
  margin: 0; padding: 1rem; color: var(--alb-muted); font-size: 0.95rem;
  border: 1.5px dashed var(--alb-line); border-radius: 12px;
}
.alb__empty[hidden] { display: none; }
.alb__restore {
  min-height: 2.75rem; padding: 0.4rem 1rem; font: inherit; font-weight: 650; cursor: pointer;
  color: var(--alb-ink); background: var(--alb-bg); border: 1.5px solid var(--alb-muted); border-radius: 10px;
}

@keyframes alb-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .alb__banner { animation: none; } }
@media (max-width: 30rem) {
  .alb__banner { gap: 0.65rem; padding: 0.8rem 0.6rem 0.8rem 0.8rem; }
}
@media (prefers-color-scheme: dark) {
  .alb {
    --alb-bg: #1c2033; --alb-ink: #eceef8; --alb-muted: #b3b9d0; --alb-line: #3d4466; --alb-focus: #ffffff;
    --alb-info-bg: #162347;    --alb-info-bar: #8fb0ff;    --alb-info-ink: #dbe6ff;
    --alb-success-bg: #10301e; --alb-success-bar: #6fd49a; --alb-success-ink: #d5f5e1;
    --alb-warning-bg: #3a2a07; --alb-warning-bar: #f2b84b; --alb-warning-ink: #ffefc6;
    --alb-error-bg: #3f1613;   --alb-error-bar: #ff9d94;   --alb-error-ink: #ffe0dd;
  }
  .alb--js .alb__dismiss:hover { background: rgba(255, 255, 255, 0.14); }
}

JavaScript

(function () {
  'use strict';

  var root = document.querySelector('.alb');
  var stack = document.getElementById('alb-stack');
  var empty = document.getElementById('alb-empty');
  var restore = document.getElementById('alb-restore');
  if (!root || !stack || !empty || !restore) return;

  // The dismiss buttons need this script, so they only appear once it runs.
  root.classList.add('alb--js');

  var originals = Array.prototype.map.call(stack.children, function (banner) {
    return banner.cloneNode(true);
  });

  stack.addEventListener('click', function (event) {
    var button = event.target.closest('.alb__dismiss');
    if (!button) return;
    var banner = button.closest('.alb__banner');
    var next = banner.nextElementSibling || banner.previousElementSibling;
    banner.remove();
    if (next) {
      next.querySelector('.alb__dismiss').focus();
    } else {
      empty.hidden = false;
      restore.focus();
    }
  });

  restore.addEventListener('click', function () {
    originals.forEach(function (banner) {
      stack.appendChild(banner.cloneNode(true));
    });
    empty.hidden = true;
    stack.querySelector('.alb__dismiss').focus();
  });
})();

Accessibility notes

Written by the author of the snippet. Each note has a test step or a markup check that reads the page.

  • Information and success use role status; warning and error use role alert.
  • Each icon has a different shape, so the kind is not told by colour alone.
  • Every dismiss button has its own name and focus moves on after a dismissal.