Component Library

← Back to gallery

Expiration badge with date in HTML, CSS and vanilla JS

A copy-paste Expiration badge with date in plain HTML and CSS, with vanilla JavaScript: no framework, no build step, MIT-licensed.

Category: Feedback · Tags: badge, state, indicator, feedback

Live preview

Source (copy-ready)

<section class="dcl-badge-expiry-date" data-dcl-scheme="light" aria-label="Expiration badge with date example">
<div data-split><div><h2>Visitor gate pass</h2><p>Receiving entrance, north desk</p></div><div data-stack data-well><span data-chip>Expires soon</span><p>Valid through <time datetime="2026-11-24">24 November 2026</time>.</p></div></div>
<script>
(() => {
  const root = document.currentScript.closest(".dcl-badge-expiry-date");
  const preference = matchMedia("(prefers-color-scheme: dark)");
  const setTheme = () => { root.dataset.dclScheme = preference.matches ? "dark" : "light"; };
  preference.addEventListener("change", setTheme);
  setTheme();
})();
</script>
</section>
<style>
.dcl-badge-expiry-date, .dcl-badge-expiry-date * { box-sizing: border-box; }
.dcl-badge-expiry-date { font: 1rem/1.5 system-ui, sans-serif; max-inline-size: 40rem; padding: clamp(0.75rem, 3vw, 1.25rem); border: 1px solid; border-radius: 0.75rem; overflow-wrap: anywhere; }
.dcl-badge-expiry-date :where(h2, h3, p, ol, ul, dl, dd) { margin: 0; }
.dcl-badge-expiry-date h2 { font-size: 1.25rem; line-height: 1.25; }
.dcl-badge-expiry-date h3 { font-size: 1rem; }
.dcl-badge-expiry-date p + p { margin-block-start: 0.5rem; }
.dcl-badge-expiry-date [data-stack], .dcl-badge-expiry-date form { display: grid; gap: 0.75rem; }
.dcl-badge-expiry-date [data-row] { display: flex; flex-wrap: wrap; gap: 0.5rem 0.75rem; align-items: center; }
.dcl-badge-expiry-date [data-split] { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr)); gap: 0.75rem 1.25rem; align-items: start; }
.dcl-badge-expiry-date [data-spread] { justify-content: space-between; }
.dcl-badge-expiry-date [hidden] { display: none !important; }
.dcl-badge-expiry-date [data-well] { padding: 0.75rem; border-radius: 0.375rem; }
.dcl-badge-expiry-date [data-chip] { display: inline-block; width: fit-content; padding: 0.125rem 0.55rem; border-radius: 99rem; font-size: 0.875rem; font-weight: 700; }
.dcl-badge-expiry-date { color-scheme: light; border-color: #697f84; }
.dcl-badge-expiry-date { color: #11292f; background-color: #ffffff; }
.dcl-badge-expiry-date [data-well], .dcl-badge-expiry-date [data-chip] { color: #11292f; background-color: #e4edef; }
.dcl-badge-expiry-date[data-dcl-scheme="dark"] { color-scheme: dark; border-color: #839fa5; }
.dcl-badge-expiry-date[data-dcl-scheme="dark"] { color: #eff8f9; background-color: #142f36; }
.dcl-badge-expiry-date[data-dcl-scheme="dark"] [data-well], .dcl-badge-expiry-date[data-dcl-scheme="dark"] [data-chip] { color: #eff8f9; background-color: #1c3c44; }
</style>

When to use

Place a time-bounded status next to a name and show the exact date below it.

Avoid

Do not use a relative countdown alone when a deadline matters.

Accessibility

A time element exposes the exact deadline; the badge expresses urgency in words. Text contrast is at least 12.7:1 in light and 10.9:1 in dark.

Was this useful? Send feedback.