Announcement Bar
Dismissible tailwind announcement bar for promos and site-wide notices.
Summer sale: 25% off all plans with code SUMMER25
Shop now<div class="w-full bg-indigo-600 text-white text-sm">
<div class="max-w-7xl mx-auto px-4 py-2.5 flex items-center justify-center gap-3">
<p class="font-medium truncate">Summer sale: 25% off all plans with code <span class="font-bold underline underline-offset-2">SUMMER25</span></p>
<a href="#" class="hidden sm:inline-block shrink-0 text-xs font-bold bg-white/15 hover:bg-white/25 rounded-full px-3 py-1 transition-colors">Shop now</a>
<button type="button" aria-label="Dismiss announcement" class="shrink-0 p-1 rounded-full hover:bg-white/15 transition-colors">
<svg class="w-4 h-4" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12"/></svg>
</button>
</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.
Emerald
Green bar for feature launches and positive news.
New: dark mode is here for every tool
Try itDark
Neutral black bar for system notices like maintenance windows.
Scheduled maintenance Sunday 2:00 AM, expect 30 min downtime
Slim
Extra thin bar that barely takes space above the navbar.
Free shipping on orders over $50
About this announcement bar
A tailwind announcement bar is the slim strip pinned to the very top of a site for things everyone should see: sales, new launches, shipping notices, maintenance windows. Marketers love the top announcement banner because it is visible on every page without covering content, and the promo bar html css pattern is simple enough to drop into any layout.
This dismissible banner tailwind snippet is a full-width colored strip with centered text, an optional CTA pill, and a close button. The text truncates on small screens so long messages never wrap into two lines and push the page down. The CTA hides below the sm breakpoint to keep phones uncluttered, and the dismiss button removes the bar with a line of JavaScript.
Use one announcement at a time; stacking bars trains users to ignore them. Keep the message under ten words and make the CTA specific. If the notice matters across visits, remember the dismissal in localStorage, but always show truly critical alerts like outages regardless of past dismissals.
Every site eventually needs to tell every visitor something: a sale, a launch, a shipping delay. Email gets ignored and popups get blocked, so the announcement bar exists as the polite broadcast channel. Pinned to the very top of every page, it is the highest-viewed element on the site without covering any content. One slim strip, one message, zero interruption to the actual page.
The bar is a full-width flex strip with centered text, an optional CTA pill, and a close button. On small screens the text truncates to a single line with an ellipsis so long messages never push the page down. The CTA hides below the sm breakpoint to keep phones to one clean row. A one-line script on the close button removes the bar, and a localStorage flag keyed to the campaign keeps it gone across visits.
Persist dismissal in localStorage keyed by the campaign id, so returning visitors aren't nagged by last week's news. When rotating messages, keep the bar height fixed; a jumping layout on every page load feels broken. For urgent alerts like outages, switch the palette to amber or red and skip the CTA; urgency and marketing don't mix. Expire time-sensitive bars automatically with a data attribute date check, or yesterday's sale haunts the site for weeks.
Do not make the entire bar a single link. Visitors aiming for the dismiss X inevitably mis-tap, landing on the promo page when they wanted the bar gone, which breeds instant resentment. Keep the message text unlinked and give the CTA its own clear target. The close button deserves the biggest, easiest target in the strip, since dismissing is the action you must never punish.
Where to use it
- ✓ Sale and promo announcements
- ✓ New feature launches
- ✓ Free shipping thresholds
- ✓ Scheduled maintenance notices
Customization tips
Swap bg-indigo-600 for any brand color, or use a gradient for seasonal campaigns. Move the CTA before the text if the action matters more than the message. For a sticky variant, add sticky top-0 z-40 so it stays visible while scrolling.
Design notes
When to use
An announcement bar fits site-wide messages everyone should see: sales, new launches, shipping notices, and maintenance windows. Pinned to the very top, it catches the eye before any scrolling happens. It works best for one timely message with one clear action, like a promo code and a shop now link.
What to avoid
Do not let a temporary announcement become permanent, because visitors develop banner blindness and stop seeing the top of your site. Avoid stacking two or three bars, since each additional strip pushes content down and breeds resentment. And do not auto-rotate messages in the bar, because nobody waits around to read the second one.
Accessibility
Provide a labeled dismiss button so keyboard users can remove the bar, and make sure its color combination meets contrast requirements. Announce the message politely rather than assertively so screen readers do not interrupt the page load announcement.
Frequently asked questions
How do I make a dismissible tailwind announcement bar?
Add a click handler on the close button that sets the bar's display to none. For persistence across page loads, also write a flag to localStorage and check it on load before rendering the bar.
Should the announcement bar be sticky?
Usually not. A static bar that scrolls away keeps the reading experience clean. Make it sticky only for time-critical messages like a sale ending today, and even then consider whether a floating badge would be less intrusive.
How do I keep long messages from breaking the layout on mobile?
Use truncate on the text so it collapses to one line with an ellipsis, and hide secondary elements like the CTA below the sm breakpoint. The bar should never grow taller than one row on phones.
How do I keep an announcement bar hidden after the user closes it?
On close, save a flag in localStorage, and on page load check that flag before rendering the bar. Key the flag to the campaign, like announcement-dismissed-sale-2026, so a new announcement appears even to users who dismissed the old one. Cookies work too, but localStorage is simpler for a purely client-side bar.
Should an announcement bar include a call to action button?
For promotions, yes: a short link like "Shop now" turns the bar from decoration into revenue. Keep it to one link, styled as an underline or a small pill button. More than one link splits attention and most visitors will click neither.
How do I make an announcement bar accessible?
Use role="region" with aria-label="Announcement" on the bar so screen readers identify it. The close button needs aria-label="Dismiss announcement" rather than relying on the X character. Do not auto-rotate messages, since changing content under a screen reader user is disorienting.