Inline Alert Banners
Info, success, warning and error banners that can be dismissed, with the right ARIA role for each.
AI prompt
Create a stack of four inline alert banners for a light interface: info (blue-grey), success (green), warning (amber) and error (red). Each has a small icon, a bold title, one sentence of body text, an optional text action ("Review changes"), and a dismiss X button at the right. Use subtle tinted backgrounds, 1 pixel borders in the same hue, 10 pixel radius, 14 pixel text with good contrast. Accessibility: error uses role alert, others role status, dismiss buttons have aria-label "Dismiss". Dismissing animates height to zero. Include a "Restore all" button. Plain HTML, CSS and JavaScript.About this pattern
Definition
An inline alert is a message that sits in the page flow near what it concerns. Unlike a toast it stays until it is dismissed or the problem is solved.
Purpose & UX principles
- Use info for neutral tips, success for completed actions, warning for risks and error for problems that block progress.
- Pair every colour with an icon and a clear sentence; give a next action when there is one.
- Errors and warnings that interrupt use role alert; informational ones use role status.
Interaction states
- Each banner has a dismiss button; Restore brings them back. Errors announce immediately; others politely.
Motion specification
- Dismiss collapses the banner height over 220ms with fade; restore reverses it.
- Reduced motion: banners disappear and appear instantly.
Responsive behaviour
- Banners span the container width; text wraps and the dismiss button stays at the top right.
- Stack multiple alerts with 8px gaps and cap them at three.
Code
<div class="bx" id="bx"></div><button id="rs" type="button">Restore all</button>:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
.bx{width:min(320px,100%);display:grid;gap:8px}
.al{display:grid;grid-template-columns:22px 1fr 24px;gap:8px;align-items:start;padding:10px 10px 10px 12px;border-radius:10px;border:1px solid var(--bd);background:var(--bgc);font-size:12.5px;line-height:1.4;overflow:hidden;max-height:90px;transition:max-height .22s ease,opacity .22s,padding .22s,margin .22s,border-width .22s}
.al.gone{max-height:0;opacity:0;padding-top:0;padding-bottom:0;margin-top:-8px;border-width:0}
.al b{display:block;font-size:13px}.al a{color:inherit;text-decoration:underline;text-underline-offset:2px;font-weight:600}
.ic{width:20px;height:20px;border-radius:50%;background:var(--ic);color:#fff;display:grid;place-items:center;font-size:12px;font-weight:700}
.x{width:24px;height:24px;border:0;background:none;border-radius:6px;cursor:pointer;font-size:15px;color:inherit;opacity:.65}.x:hover{opacity:1;background:rgba(0,0,0,.06)}
.info{--bd:#c9d6e6;--bgc:#f1f6fc;--ic:#3b6ea5}.ok{--bd:#bfe1cb;--bgc:#f0faf3;--ic:#1a8f4a}.warn{--bd:#efd9a6;--bgc:#fff8e6;--ic:#b87500}.err{--bd:#f0c0bb;--bgc:#fff2f1;--ic:#d92d20}
#rs{margin-top:10px;height:28px;padding:0 14px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:12px;cursor:pointer}
button:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
@media (prefers-reduced-motion:reduce){.al{transition:none}}const A=[['info','i','Tip','You can drag cards to reorder them.'],['ok','✓','Saved','Your changes are live.'],['warn','!','Storage almost full','You have used 92% of your space. <a href="#" onclick="return false">Manage files</a>'],['err','×','Payment failed','Your card was declined. <a href="#" onclick="return false">Update card</a>']],bx=document.getElementById('bx');
function build(){bx.innerHTML='';A.forEach(a=>{const d=document.createElement('div');d.className='al '+a[0];d.setAttribute('role',a[0]==='err'?'alert':'status');d.innerHTML='<span class="ic" aria-hidden="true">'+a[1]+'</span><div><b>'+a[2]+'</b>'+a[3]+'</div><button class="x" type="button" aria-label="Dismiss">×</button>';
d.querySelector('.x').addEventListener('click',()=>{d.classList.add('gone');d.setAttribute('aria-hidden','true');d.querySelectorAll('a,button').forEach(e=>e.tabIndex=-1);});bx.append(d);});}
document.getElementById('rs').addEventListener('click',build);build();One complete HTML file. Save it and open it in a browser.
<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Inline Alert Banners — demo</title>
<style>
:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
html,body{height:100%}body{background:var(--bg);color:var(--text);font:15px/1.5 -apple-system,BlinkMacSystemFont,'Segoe UI',Inter,Roboto,sans-serif;-webkit-font-smoothing:antialiased}.stage{min-height:100%;display:grid;place-items:center;padding:24px}button,input,select,textarea{font-family:inherit}@media (prefers-reduced-motion:reduce){html{scroll-behavior:auto}}
.bx{width:min(320px,100%);display:grid;gap:8px}
.al{display:grid;grid-template-columns:22px 1fr 24px;gap:8px;align-items:start;padding:10px 10px 10px 12px;border-radius:10px;border:1px solid var(--bd);background:var(--bgc);font-size:12.5px;line-height:1.4;overflow:hidden;max-height:90px;transition:max-height .22s ease,opacity .22s,padding .22s,margin .22s,border-width .22s}
.al.gone{max-height:0;opacity:0;padding-top:0;padding-bottom:0;margin-top:-8px;border-width:0}
.al b{display:block;font-size:13px}.al a{color:inherit;text-decoration:underline;text-underline-offset:2px;font-weight:600}
.ic{width:20px;height:20px;border-radius:50%;background:var(--ic);color:#fff;display:grid;place-items:center;font-size:12px;font-weight:700}
.x{width:24px;height:24px;border:0;background:none;border-radius:6px;cursor:pointer;font-size:15px;color:inherit;opacity:.65}.x:hover{opacity:1;background:rgba(0,0,0,.06)}
.info{--bd:#c9d6e6;--bgc:#f1f6fc;--ic:#3b6ea5}.ok{--bd:#bfe1cb;--bgc:#f0faf3;--ic:#1a8f4a}.warn{--bd:#efd9a6;--bgc:#fff8e6;--ic:#b87500}.err{--bd:#f0c0bb;--bgc:#fff2f1;--ic:#d92d20}
#rs{margin-top:10px;height:28px;padding:0 14px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:12px;cursor:pointer}
button:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
@media (prefers-reduced-motion:reduce){.al{transition:none}}
</style></head>
<body><div class="stage">
<div class="bx" id="bx"></div><button id="rs" type="button">Restore all</button>
</div>
<script>
const A=[['info','i','Tip','You can drag cards to reorder them.'],['ok','✓','Saved','Your changes are live.'],['warn','!','Storage almost full','You have used 92% of your space. <a href="#" onclick="return false">Manage files</a>'],['err','×','Payment failed','Your card was declined. <a href="#" onclick="return false">Update card</a>']],bx=document.getElementById('bx');
function build(){bx.innerHTML='';A.forEach(a=>{const d=document.createElement('div');d.className='al '+a[0];d.setAttribute('role',a[0]==='err'?'alert':'status');d.innerHTML='<span class="ic" aria-hidden="true">'+a[1]+'</span><div><b>'+a[2]+'</b>'+a[3]+'</div><button class="x" type="button" aria-label="Dismiss">×</button>';
d.querySelector('.x').addEventListener('click',()=>{d.classList.add('gone');d.setAttribute('aria-hidden','true');d.querySelectorAll('a,button').forEach(e=>e.tabIndex=-1);});bx.append(d);});}
document.getElementById('rs').addEventListener('click',build);build();
</script>
</body></html>