December starts tomorrow, so here's a small thing I built for it: an advent calendar you can drop on any website. A gift button sits in the corner, it opens a calendar of 24 doors, and each door hides a message, a discount code or a link. Only today's door and the earlier ones open; future doors shake and tell you when they unlock.
It's free and MIT, no dependencies, about 16 KB minified. Try it here (every door is unlocked in the demo):
Install
<script src="https://cdn.jsdelivr.net/npm/@fluritheme/advent-calendar@1/dist/advent-calendar.global.js" data-auto></script> Or with npm:
import { createAdventCalendar } from "@fluritheme/advent-calendar"; const calendar = createAdventCalendar({ title: "Our Advent Calendar", days: [ { title: "Welcome to December", text: "Free shipping today.", code: "DEC1" }, { title: "Day 2", text: "10% off scarves.", code: "SCARF10", link: "https://example.com/scarves" }, ], onOpen: (day) => console.log("Opened door", day), }); Days you leave out get a built-in festive note, so you can fill in only the days you have offers for.
Whose midnight?
The interesting part of an advent calendar on the web is the date. If doors unlocked by a server's clock, a visitor in Sydney and a visitor in New York would get tomorrow's door at the wrong time for at least one of them. A paper calendar on your kitchen wall opens at your midnight, so the web one should too.
So the calendar works entirely with the visitor's own clock. "Today" is a small function that returns a day number for the calendar month: 0 before it starts, the date during it, and count + 1 after it ends:
function today() { const n = now(), y = year(), m = month - 1; if (n.getFullYear() < y || (n.getFullYear() === y && n.getMonth() < m)) return 0; if (n.getFullYear() > y || n.getMonth() > m) return count + 1; return n.getDate(); } const canOpen = (d) => unlockAll || d <= today(); That one number drives everything: which doors open, whether the button shows at all (it appears on 1 December and hides itself a week after the last door), and the little reminder bubble when today's door is still closed.
Two small things that matter:
- Pages left open overnight. People leave shop tabs open for days. The calendar re-checks the date every minute when it's closed, so the next door unlocks without a reload.
- Testing in November. You can't wait for December to see if it works. There's a
nowoption that overrides "today", andunlockAll: truefor demos like the pen above.
Making it feel like a printed calendar
Doors numbered 1 to 24 in order look like a spreadsheet. Printed calendars scatter them, so the doors use a fixed, hand-picked order (7, 18, 3, 12, 22, 1…). It's fixed on purpose: a random shuffle would move the doors between visits, and regulars would have to hunt for today's door every day.
Opening a door swings it on its hinge first and only then shows what's behind it. With prefers-reduced-motion the swing is skipped and the content just appears.
No cookies, no network
Opened doors are remembered in localStorage, nothing else is stored, and it makes no network requests. All the markup and styles live in a shadow root, so your CSS can't break it and it can't break yours. Esc closes it and the doors are real buttons, so it works from the keyboard.
It's one of the free, MIT-licensed packages behind Fluri, my collection of interactive website effects. If you run WordPress, Shopify or Wix there's a no-code version with live settings.
If you add it to a shop this December, what would you hide behind door 24?
npm: https://www.npmjs.com/package/@fluritheme/advent-calendar


