6 CSS Countdown Timers 02 / 06

Website Sticky Announcement Bars (Site-Wide)

An ultra-thin, flexbox-aligned strip pinned to the top of the viewport, broadcasting a free-shipping deadline.

Best forsite-wide promo bars, shipping cutoff alerts, holiday campaign chrome, and any persistent deadline that should never scroll away.

CSS + JS MIT licensed
Live Demo Open in tab
Open in playground

The code

<section class="cdt-stk" aria-label="Sticky announcement bar countdown demo">
  <div class="cdt-stk__announce">
    <div class="cdt-stk__inner">
      <span class="cdt-stk__ship-icon" aria-hidden="true">
        <svg viewBox="0 0 24 24"><path d="M3 13V6a1 1 0 0 1 1-1h11v8H3zm13 0V8h3l3 3v2h-1a2 2 0 1 0-4 0h-1zm-9 4a2 2 0 1 1 0-.001zM18 17a2 2 0 1 1 0-.001z"/></svg>
      </span>
      <span class="cdt-stk__msg">🎉 <span class="cdt-stk__hl">FREE express shipping</span> on all orders — ends midnight!</span>
      <span class="cdt-stk__divider" aria-hidden="true"></span>
      <div class="cdt-stk__countdown" role="timer" aria-live="polite" aria-atomic="true">
        <span class="cdt-stk__lbl">Ends in</span>
        <span class="cdt-stk__unit" data-cdt-stk="h">05</span>
        <span class="cdt-stk__sep" aria-hidden="true">:</span>
        <span class="cdt-stk__unit" data-cdt-stk="m">00</span>
        <span class="cdt-stk__sep" aria-hidden="true">:</span>
        <span class="cdt-stk__unit" data-cdt-stk="s">00</span>
      </div>
      <a href="#" class="cdt-stk__cta-link">Shop Now</a>
    </div>
  </div>

  <div class="cdt-stk__page">
    <h2 class="cdt-stk__h2">Your storefront content</h2>
    <p class="cdt-stk__p">The announcement strip above stays pinned to the top of the section as visitors scroll. It is built with a flexbox-aligned inline layout, a compact monospace clock, and clean translucent borders that flow naturally with a site header.</p>
    <div class="cdt-stk__ghost"></div><div class="cdt-stk__ghost"></div><div class="cdt-stk__ghost cdt-stk__ghost--s"></div>
    <p class="cdt-stk__p">Scroll this card to confirm the bar remains fixed. The blinking colon separators reinforce that the deadline is live and ticking.</p>
    <div class="cdt-stk__ghost"></div><div class="cdt-stk__ghost"></div><div class="cdt-stk__ghost"></div><div class="cdt-stk__ghost cdt-stk__ghost--s"></div>
    <p class="cdt-stk__hint">↑ The bar stays put while you scroll ↑</p>
  </div>
</section>
/* ─── 02 Sticky Announcement Bar — site-wide countdown ──────── */
@import url('https://fonts.googleapis.com/css2?family=Sora:wght@400;600;700&family=DM+Mono:wght@500&display=swap');

.cdt-stk {
  --cdt-stk-bar-bg: #0d1b2a;
  --cdt-stk-accent: #4ee1a0;
  --cdt-stk-accent-2: #7cc6fe;
  --cdt-stk-text: #eef4f8;

  position: relative;
  width: 100%;
  height: 560px;
  background: linear-gradient(180deg, #c7d4dc 0%, #9fb2bd 100%);
  font-family: 'Sora', sans-serif;
  display: flex; flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  box-sizing: border-box;
}
.cdt-stk *, .cdt-stk *::before, .cdt-stk *::after { box-sizing: border-box; margin: 0; padding: 0; }

.cdt-stk__announce {
  position: sticky; top: 0; z-index: 100;
  width: 100%;
  background: var(--cdt-stk-bar-bg);
  background-image:
    radial-gradient(circle at 15% 50%, rgba(78,225,160,0.18), transparent 35%),
    radial-gradient(circle at 85% 50%, rgba(124,198,254,0.15), transparent 35%);
  color: var(--cdt-stk-text);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  box-shadow: 0 4px 24px rgba(13,27,42,0.25);
}
.cdt-stk__inner {
  max-width: 1180px; margin: 0 auto;
  padding: 11px 22px;
  display: flex; align-items: center; gap: 16px;
  flex-wrap: wrap; justify-content: center;
}
.cdt-stk__ship-icon {
  width: 22px; height: 22px; border-radius: 50%;
  background: linear-gradient(135deg, var(--cdt-stk-accent), var(--cdt-stk-accent-2));
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; box-shadow: 0 0 14px rgba(78,225,160,0.5);
}
.cdt-stk__ship-icon svg { width: 13px; height: 13px; fill: var(--cdt-stk-bar-bg); }
.cdt-stk__msg { font-size: 14px; font-weight: 600; letter-spacing: 0.2px; }
.cdt-stk__hl  { color: var(--cdt-stk-accent); }
.cdt-stk__divider { width: 1px; height: 18px; background: rgba(255,255,255,0.15); }
.cdt-stk__countdown {
  display: flex; align-items: center; gap: 6px;
  font-family: 'DM Mono', monospace;
}
.cdt-stk__lbl {
  font-family: 'Sora', sans-serif;
  font-size: 12px; opacity: 0.65; margin-right: 4px; letter-spacing: 0.5px;
}
.cdt-stk__unit {
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px; padding: 4px 8px;
  font-size: 14px; font-weight: 500;
  min-width: 30px; text-align: center; color: var(--cdt-stk-text);
}
.cdt-stk__sep {
  color: var(--cdt-stk-accent); font-weight: 700;
  animation: cdt-stk-flick 1s steps(1) infinite;
}
@keyframes cdt-stk-flick { 50% { opacity: 0.25; } }
.cdt-stk__cta-link {
  font-size: 13px; font-weight: 700;
  color: var(--cdt-stk-bar-bg); background: var(--cdt-stk-accent);
  padding: 7px 16px; border-radius: 20px;
  text-decoration: none; white-space: nowrap;
  transition: transform 0.15s, box-shadow 0.2s;
}
.cdt-stk__cta-link:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(78,225,160,0.4); }
.cdt-stk__cta-link:focus-visible { outline: 2px solid var(--cdt-stk-bar-bg); outline-offset: 2px; }

.cdt-stk__page { flex: 1; padding: 60px 24px; max-width: 760px; margin: 0 auto; color: #2b3a44; }
.cdt-stk__h2   { font-size: 22px; margin-bottom: 14px; font-weight: 700; color: #1c2a33; }
.cdt-stk__p    { line-height: 1.8; margin-bottom: 16px; opacity: 0.8; font-size: 14px; }
.cdt-stk__ghost { height: 12px; background: rgba(43,58,68,0.12); border-radius: 6px; margin-bottom: 10px; }
.cdt-stk__ghost--s { width: 60%; }
.cdt-stk__hint  { text-align: center; font-size: 12px; opacity: 0.55; margin-top: 30px; }

@media (max-width: 600px) {
  .cdt-stk__divider { display: none; }
  .cdt-stk__inner   { gap: 10px; padding: 10px 14px; }
  .cdt-stk__msg     { font-size: 12.5px; text-align: center; }
}
@media (prefers-reduced-motion: reduce) {
  .cdt-stk__sep, .cdt-stk__cta-link { animation: none; transition: none; }
}
(() => {
  const root = document.querySelector('.cdt-stk');
  if (!root) return;
  const target = Date.now() + (5*3600 + 12*60 + 47) * 1000;
  const pad = (n) => String(n).padStart(2, '0');
  const h = root.querySelector('[data-cdt-stk="h"]');
  const m = root.querySelector('[data-cdt-stk="m"]');
  const s = root.querySelector('[data-cdt-stk="s"]');
  function tick() {
    const diff = Math.max(0, target - Date.now());
    h.textContent = pad(Math.floor(diff / 3600000));
    m.textContent = pad(Math.floor(diff % 3600000 / 60000));
    s.textContent = pad(Math.floor(diff % 60000 / 1000));
  }
  tick();
  setInterval(tick, 1000);
})();

Search CodeFronts

Loading…