Announcement Banner
A dismissible bar at the top of the page in info, success, warning and promo styles.
AI prompt
Clean website mockup with a slim full-width announcement banner above the header: a pale blue bar with a small info icon, the text New: dark mode is here, a text link Try it, and a close cross on the right, rounded app UI below it in light grey, flat modern style, subtle border, no shadows. Variants: green success, amber warning, and a dark promo banner with a white button. Negative: multiple banners, heavy gradients, popups, text errors, clutter. Reduced motion: static design.About this pattern
Definition
An announcement banner carries one message that applies to the whole page or site: a launch, a maintenance window, a sale. It sits above the header, stays until dismissed and collapses smoothly so the page below does not jump.
Purpose & UX principles
- One message, one action, one close button; the text should fit on a single line on desktop.
- Choose the tone by role: info for news, success for confirmations, warning for risk, promo for offers.
- Remember dismissal so it does not return on every page.
Interaction states
- Four style buttons, a dismiss button on the banner and a Show again button.
Motion specification
- Dismiss collapses the height over 250ms using a grid row transition.
- Reduced motion: the banner disappears immediately.
Responsive behaviour
- On narrow screens let the text wrap to two lines and keep the close button reachable.
- Do not stack more than one banner.
Code
<div class="bx"><div class="pre" id="pre" role="group" aria-label="Style"><button data-p="0" aria-pressed="true">Info</button><button data-p="1" aria-pressed="false">Success</button><button data-p="2" aria-pressed="false">Warning</button><button data-p="3" aria-pressed="false">Promo</button></div><div class="pg"><div class="wr" id="wr"><div class="in"><div class="bn" id="bn" role="status"><span class="ic" id="ic"></span><span id="tx"></span><a href="#" id="ln">Learn more</a><button type="button" id="cl" aria-label="Dismiss announcement">×</button></div></div></div><div class="hd">Product name<span></span></div></div><button class="mini" id="sa" type="button" hidden>Show again</button></div>: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}
button{font:inherit;color:inherit;background:none;border:0;padding:0;cursor:pointer}a{color:inherit;text-decoration:none}ul,ol,p,h4{margin:0;padding:0}.sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
.pre{display:flex;gap:5px;flex-wrap:wrap}.pre button{height:28px;padding:0 11px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:11px;cursor:pointer}
.pre button[aria-pressed=true]{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
.bx{width:min(330px,100%);display:grid;gap:9px}.rw{display:grid;gap:3px;font-size:11.5px;color:var(--muted)}.rw b{color:var(--text);font-weight:600}input[type=range]{width:100%;accent-color:#171717}
.out{font-size:12px;color:var(--muted);line-height:1.4}.out b{color:var(--text)}
button:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.pg{border:1px solid var(--line);border-radius:12px;overflow:hidden;background:var(--surface);min-height:130px}.hd{padding:12px 14px;font-weight:700;font-size:14px;display:flex;justify-content:space-between}.hd span{width:60px;height:8px;border-radius:4px;background:var(--pv);align-self:center}
.wr{display:grid;grid-template-rows:1fr;transition:grid-template-rows .25s}.wr.off{grid-template-rows:0fr}.in{overflow:hidden}
.bn{display:flex;align-items:center;gap:10px;padding:9px 14px;font-size:12.5px;background:var(--bb);color:var(--bt)}.bn a{margin-left:4px;font-weight:600;text-decoration:underline;white-space:nowrap}.bn button{margin-left:auto;font-size:18px;line-height:1;width:26px;height:26px;border-radius:50%}.bn button:hover{background:rgba(0,0,0,.08)}.ic{width:16px;height:16px;border-radius:50%;background:currentColor;display:grid;place-items:center;font-size:10px;color:var(--bt);position:relative;flex:none}.ic::after{content:attr(data-g);color:var(--bb);font-weight:800;position:absolute}
.mini{height:30px;padding:0 14px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:12px;font-weight:600;cursor:pointer}.mini:disabled{opacity:.4;cursor:default}@media (prefers-reduced-motion:reduce){.wr{transition:none}}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}const S=[['#e8f0ff','#16347a','i','New: dark mode is now available.'],['#e3f6ea','#14502a','\u2713','Your changes were published.'],['#fff3d6','#6a4800','!','Scheduled maintenance tonight at 22:00 UTC.'],['#171717','#ffffff','%','Spring sale: 30% off all plans this week.']],wr=document.getElementById('wr'),bn=document.getElementById('bn'),sa=document.getElementById('sa'),bs=[...document.querySelectorAll('#pre button')];let p=0;
function up(){const s=S[p];bn.style.setProperty('--bb',s[0]);bn.style.setProperty('--bt',s[1]);document.getElementById('ic').dataset.g=s[2];document.getElementById('tx').textContent=s[3];wr.classList.remove('off');sa.hidden=true;bs.forEach(b=>b.setAttribute('aria-pressed',String(+b.dataset.p===p)));}
document.getElementById('ln').addEventListener('click',e=>e.preventDefault());document.getElementById('cl').addEventListener('click',()=>{wr.classList.add('off');sa.hidden=false;sa.focus();});sa.addEventListener('click',()=>{wr.classList.remove('off');sa.hidden=true;});
bs.forEach(b=>b.addEventListener('click',()=>{p=+b.dataset.p;up();}));up();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>Announcement Banner — 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}}
button{font:inherit;color:inherit;background:none;border:0;padding:0;cursor:pointer}a{color:inherit;text-decoration:none}ul,ol,p,h4{margin:0;padding:0}.sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
.pre{display:flex;gap:5px;flex-wrap:wrap}.pre button{height:28px;padding:0 11px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:11px;cursor:pointer}
.pre button[aria-pressed=true]{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
.bx{width:min(330px,100%);display:grid;gap:9px}.rw{display:grid;gap:3px;font-size:11.5px;color:var(--muted)}.rw b{color:var(--text);font-weight:600}input[type=range]{width:100%;accent-color:#171717}
.out{font-size:12px;color:var(--muted);line-height:1.4}.out b{color:var(--text)}
button:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.pg{border:1px solid var(--line);border-radius:12px;overflow:hidden;background:var(--surface);min-height:130px}.hd{padding:12px 14px;font-weight:700;font-size:14px;display:flex;justify-content:space-between}.hd span{width:60px;height:8px;border-radius:4px;background:var(--pv);align-self:center}
.wr{display:grid;grid-template-rows:1fr;transition:grid-template-rows .25s}.wr.off{grid-template-rows:0fr}.in{overflow:hidden}
.bn{display:flex;align-items:center;gap:10px;padding:9px 14px;font-size:12.5px;background:var(--bb);color:var(--bt)}.bn a{margin-left:4px;font-weight:600;text-decoration:underline;white-space:nowrap}.bn button{margin-left:auto;font-size:18px;line-height:1;width:26px;height:26px;border-radius:50%}.bn button:hover{background:rgba(0,0,0,.08)}.ic{width:16px;height:16px;border-radius:50%;background:currentColor;display:grid;place-items:center;font-size:10px;color:var(--bt);position:relative;flex:none}.ic::after{content:attr(data-g);color:var(--bb);font-weight:800;position:absolute}
.mini{height:30px;padding:0 14px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:12px;font-weight:600;cursor:pointer}.mini:disabled{opacity:.4;cursor:default}@media (prefers-reduced-motion:reduce){.wr{transition:none}}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}
</style></head>
<body><div class="stage">
<div class="bx"><div class="pre" id="pre" role="group" aria-label="Style"><button data-p="0" aria-pressed="true">Info</button><button data-p="1" aria-pressed="false">Success</button><button data-p="2" aria-pressed="false">Warning</button><button data-p="3" aria-pressed="false">Promo</button></div><div class="pg"><div class="wr" id="wr"><div class="in"><div class="bn" id="bn" role="status"><span class="ic" id="ic"></span><span id="tx"></span><a href="#" id="ln">Learn more</a><button type="button" id="cl" aria-label="Dismiss announcement">×</button></div></div></div><div class="hd">Product name<span></span></div></div><button class="mini" id="sa" type="button" hidden>Show again</button></div>
</div>
<script>
const S=[['#e8f0ff','#16347a','i','New: dark mode is now available.'],['#e3f6ea','#14502a','\u2713','Your changes were published.'],['#fff3d6','#6a4800','!','Scheduled maintenance tonight at 22:00 UTC.'],['#171717','#ffffff','%','Spring sale: 30% off all plans this week.']],wr=document.getElementById('wr'),bn=document.getElementById('bn'),sa=document.getElementById('sa'),bs=[...document.querySelectorAll('#pre button')];let p=0;
function up(){const s=S[p];bn.style.setProperty('--bb',s[0]);bn.style.setProperty('--bt',s[1]);document.getElementById('ic').dataset.g=s[2];document.getElementById('tx').textContent=s[3];wr.classList.remove('off');sa.hidden=true;bs.forEach(b=>b.setAttribute('aria-pressed',String(+b.dataset.p===p)));}
document.getElementById('ln').addEventListener('click',e=>e.preventDefault());document.getElementById('cl').addEventListener('click',()=>{wr.classList.add('off');sa.hidden=false;sa.focus();});sa.addEventListener('click',()=>{wr.classList.remove('off');sa.hidden=true;});
bs.forEach(b=>b.addEventListener('click',()=>{p=+b.dataset.p;up();}));up();
</script>
</body></html>