CodeChroma All articles
Accessibility & Colour Systems

Behind Every Flap: A 24-Door Advent Palette That Welcomes Every Visitor

CodeChroma
Behind Every Flap: A 24-Door Advent Palette That Welcomes Every Visitor

Photo: traditional UK advent calendar chocolate box foil doors close up, via images.squarespace-cdn.com

Advent calendars are tiny theatre. Twenty-four flaps, a bit of foil, and the promise that tomorrow will be slightly more chocolatey than today. On the web, that theatre often becomes a grid of divs that looks lovely in a screenshot and falls apart the moment someone tabs through it. This year I wanted a calendar that kept the chocolate-box charm but behaved like a proper interface: keyboard-friendly, readable in dark mode, and calm for anyone who has asked their browser to reduce motion.

Start with the shelf, not the screen

Traditional UK advent calendars are a useful colour reference because they are unashamedly decorative but also constrained. You get robin red, holly green, midnight blue, fondant pink, gold foil, and that creamy paper that smells faintly of cardboard and anticipation. I sampled a handful of cheap and not-so-cheap calendars and pulled out five recurring notes: bright foil highlights, powdery mid-tones, deep ink outlines, a warm paper base, and one or two surprise accents that stop the whole thing feeling like a school worksheet.

That is the mood board. The interface needs something stricter. OKLCH is a good fit because lightness and chroma are easier to reason about than hex codes. A door can be cheerful without becoming a glare hazard, and a dark-mode variant can keep the same hue family while dropping the paper brightness.

Twenty-four tokens, not twenty-four guesses

The calendar uses one token per door plus a shared paper, ink and focus colour. The door tokens are generated, not hand-picked, so the set feels varied but consistent.

:root {
  --paper: oklch(96% 0.02 85);
  --ink: oklch(24% 0.03 60);
  --focus: oklch(62% 0.18 250);
  --door-l: 72%;
  --door-c: 0.11;
}

.advent {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: clamp(0.5rem, 1.5vw, 1rem);
}

.door {
  aspect-ratio: 1;
  border: 2px solid var(--ink);
  border-radius: 0.4rem;
  background: var(--door-bg, var(--paper));
  color: var(--door-ink, var(--ink));
  font: inherit;
  position: relative;
}

.door:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.door[aria-expanded='true'] {
  background: var(--paper);
  color: var(--ink);
}

On a narrow phone the grid becomes three columns. That is a layout decision, but it is also an accessibility one: tiny doors are hard to hit with a thumb, and a 6-by-4 grid at 320px wide turns each flap into a pixel-hunting exercise.

Markup that behaves

Each door is a real button, not a div with a click handler. It gets an accessible name, an expanded state and a relationship to the panel it controls. The panel stays in the DOM but is hidden until the door opens.

<button class='door' aria-expanded='false' aria-controls='door-1'>
  <span aria-hidden='true'>1</span>
  <span class='sr-only'>Open door 1</span>
</button>
<div id='door-1' hidden>...</div>

The JavaScript is deliberately small: toggle aria-expanded, toggle hidden, and keep focus on the button. No focus traps, no custom arrow-key navigation that only works if you already know the trick. Tab moves through the doors in order, Enter or Space opens one, and Escape closes it. If a maker wants to add a roving tabindex later, the markup can take it, but the simple version is the one that ships first.

Focus styles matter more than usual here because the doors are decorative. A strong outline in a contrasting hue keeps the calendar usable without turning every door into a permanent ring of colour. The focus colour is the one token I do not generate; it should be predictable across all 24 cells.

A canvas shimmer with an off switch

The foil effect is a small canvas layer behind the door numbers. It draws a soft diagonal gradient and nudges the highlight with a slow sine wave. The point is not to recreate a £2 calendar in WebGL; it is to add a bit of seasonal texture without making the page expensive to paint.

const reduce = matchMedia('(prefers-reduced-motion: reduce)');
function drawFoil(t) {
  if (reduce.matches) {
    ctx.clearRect(0, 0, canvas.width, canvas.height);
    return;
  }
  ctx.clearRect(0, 0, canvas.width, canvas.height);
  const x = (Math.sin(t / 4000) * 0.5 + 0.5) * canvas.width;
  const grad = ctx.createLinearGradient(0, 0, x, canvas.height);
  grad.addColorStop(0, 'transparent');
  grad.addColorStop(0.5, 'oklch(88% 0.12 85 / 0.35)');
  grad.addColorStop(1, 'transparent');
  ctx.fillStyle = grad;
  ctx.fillRect(0, 0, canvas.width, canvas.height);
  requestAnimationFrame(drawFoil);
}

The canvas is marked aria-hidden='true' because it is decoration. When reduced motion is requested, it clears once and stops. That is the whole fallback: no shimmer, no loop, no hidden animation still burning battery in a background tab.

Dark mode: the kitchen at night

The dark variant is not a simple invert. The paper becomes a deep warm grey, the ink becomes a soft cream, and the door backgrounds keep their hue but lose a little lightness and chroma. Foil highlights get quieter. The calendar should feel like the kitchen at 11pm, not a neon sign in a shop window.

@media (prefers-color-scheme: dark) {
  :root {
    --paper: oklch(22% 0.02 70);
    --ink: oklch(92% 0.02 85);
    --focus: oklch(78% 0.14 250);
  }
  .door {
    border-color: oklch(70% 0.02 70);
  }
}

The important part is that the door text colour is set per door, not inherited from one global ink. A light door needs a dark label; a darker door needs a light one. The generator handles that pairing.

The door-hue generator

A calendar with 24 manually chosen colours drifts. One door is too similar to its neighbour, another disappears against the paper. A small generator keeps the set varied and predictable.

const goldenAngle = 137.508;

function doorHue(i, base = 18) {
  return (base + i * goldenAngle) % 360;
}

function doorTokens(i) {
  const h = doorHue(i);
  const l = 68 + (i % 3) * 5;
  const c = 0.09 + (i % 4) * 0.01;
  const bg = `oklch(${l}% ${c} ${h})`;
  const ink = l > 70
    ? `oklch(24% 0.03 ${h})`
    : `oklch(96% 0.02 ${h})`;
  return { '--door-bg': bg, '--door-ink': ink };
}

That is the starting point, not the final answer. The generator then checks each background and ink pair against the paper and against the label colour. If a pair falls below 4.5:1 for normal text, it nudges lightness until the pair clears the threshold. The check is the boring part; the golden angle is the bit that makes the calendar feel hand-picked.

Wrapping it up

An advent calendar is a lovely excuse to play with colour, but it is also a small interface with real users. Keep the buttons real, keep the focus visible, let the foil rest when motion is reduced, and generate door hues with a contrast check attached. Then the only thing left to argue about is whether door 24 should be the biggest chocolate or the smallest. That is a design decision no token set can settle.

All Articles

Related Articles

The Judge's Table: A Rosette-Inspired Ranking System That Keeps Colour in Its Place

The Judge's Table: A Rosette-Inspired Ranking System That Keeps Colour in Its Place

Steeping the Spinner: A Tea-Rack Colour Ramp for Loading States

Steeping the Spinner: A Tea-Rack Colour Ramp for Loading States

Roll Up, Roll Up: A Fete-Ready Tombola Ticket Press for Screens and Cheap Printers

Roll Up, Roll Up: A Fete-Ready Tombola Ticket Press for Screens and Cheap Printers