Skip to content

Promo Banner with Countdown

Dark Tailwind CSS sale banner with a live countdown timer, discount code, call-to-action button and a dismiss control.

Also known as: sale countdown banner, promotional banner with timer, discount offer banner, limited time offer banner

Tailwind CSS Promo Banners Responsive Dark #banner #countdown #dark #responsive #sale

Promo Banner with Countdown live demo

Open in new tab

Tailwind CSS code (HTML, CSS, JS)

A dark, high-contrast sale banner built with Tailwind CSS and vanilla JavaScript. It combines a bold headline, a discount code, a live days/hours/minutes/seconds countdown and a call-to-action button, and the visitor can dismiss it. Use it on a home page, category page or cart to push a limited-time offer.

How it works

The root is .tpb-promo, a light backdrop that holds the banner itself, an aside marked data-tpb-banner. On phones and tablets the content stacks; from lg up the headline and the countdown sit side by side using lg:grid-cols-[1.2fr_auto]. In style.css, .tpb-stripes paints a diagonal stripe texture with repeating-linear-gradient and fades it out with a mask.

On DOMContentLoaded the script initializes every .tpb-promo. It reads the deadline from data-tpb-end, an ISO 8601 date; if that attribute is missing or invalid it counts down data-tpb-hours from page load (72 hours by default), which is what the demo uses. Every second tick() writes zero-padded values into the four data-tpb-unit elements and the seconds digit replays the short tpb-tick animation. A visually hidden data-tpb-deadline paragraph states the exact end date in the visitor's locale. When time runs out, expire() hides the timer, changes the data-tpb-label text to "This sale has ended", disables the data-tpb-cta link and sets data-tpb-expired on the root.

Clicking the data-tpb-dismiss button (or pressing Escape while focus is inside the banner) plays the tpb-leaving animation, then hides the root and stops the interval. If data-tpb-remember has a value, the dismissal is saved in localStorage and the banner stays hidden on later visits.

Customization

  • data-tpb-end on .tpb-promo: set a fixed deadline such as 2026-12-31T23:59:59Z; it overrides data-tpb-hours.
  • data-tpb-hours="53.5": change the rolling demo duration, or remove it when you use a fixed end date.
  • data-tpb-remember: give it a campaign name like winter-sale to remember dismissals per campaign; leave it empty to show the banner on every visit.
  • bg-lime-300 and text-lime-300: swap lime for amber or pink to recolor the badge, digits and button.
  • bg-zinc-950 on data-tpb-banner: use another dark tone such as bg-indigo-950.
  • rgb(190 242 100 / 0.07) in .tpb-stripes: make the stripes stronger or remove the element for a flat background.
  • href="#" on data-tpb-cta: point it at your sale collection.

Use cases

  • Online stores: a dark sale banner with a live countdown pushes a limited-time offer on the home page
  • Category and cart pages: the discount code and call-to-action button remind shoppers to finish buying before time runs out
  • Seasonal campaigns: set a fixed end date so the banner shows days, hours, minutes and seconds left
  • Newsletters and landing pages: visitors dismiss the banner and it stays hidden on later visits if remembered

Accessibility

The banner is an aside labelled by its h2. The countdown uses role="timer", which is not announced on every tick, and is labelled by "Ends in" and described by the hidden deadline sentence, so screen reader users hear one clear end date instead of changing numbers. The dismiss button has a visually hidden label, and decorative icons, the glow and the stripes are aria-hidden. The expired link gets aria-disabled="true". White and lime text on near-black exceeds WCAG AA contrast, every control has a visible lime focus outline, and the tick and dismiss animations are disabled under prefers-reduced-motion.

Usage notes

The countdown runs on the visitor's clock; for strict deadlines, render data-tpb-end from the server and validate the discount code at checkout.

Promo Banner with Countdown at a glance

Framework
Tailwind CSS
Code
HTML, CSS, JavaScript
JavaScript
Vanilla JavaScript, no jQuery
Dependencies
Tailwind CSS
Layout
Responsive, works on mobile, dark design
Category
Promo Banners
License
Free for personal and commercial use

Questions about this template

Can I use the Promo Banner with Countdown code for free?

Yes. You can copy or download the code and use it in personal and commercial projects, including client work. No sign-up is needed. Reselling it as part of a component library or template collection is not allowed; see the license.

How do I add it to my website?

Load Tailwind CSS from a CDN (the links are under Requirements). Paste the HTML where the component should appear, add the CSS to your stylesheet and load the JavaScript before the closing </body> tag. Download HTML gives you a complete page with everything already linked.

Does it need jQuery or a JavaScript framework?

No. The script is plain vanilla JavaScript, so it works without jQuery, React or Vue. You can still use the markup inside those frameworks.

Does it work on mobile?

Yes. The layout adapts to small screens. Use the Mobile and Tablet buttons above the live demo to check it at phone and tablet width.

Requirements

Add these to your page (already included in the download):

  • <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>

The Tailwind browser build is for prototyping. In production, compile Tailwind with its CLI or your bundler.

Promo Banner with Countdown – free Tailwind CSS promo banner template
Promo Banner with Countdown · free Tailwind CSS promo banner template

More Promo Banners

Coupon Ticket – free Pure CSS promo banner template

Coupon Ticket

Ticket-style discount coupon with a striped stub, dashed perforation with notches and a copy code button with clipboard fallback and live feedback.