Split-flap countdown
A countdown built like an old station board: every digit is a real two-part flap that folds over with moving shadows, the colon pulses with the seconds and the board flashes at zero.
"use client";
import { useEffect, useState, type CSSProperties } from "react";
import "./flip-clock.css";
/**
* One split-flap digit. When the value changes, the top half of the old card falls forward
* and the bottom half of the new card swings down to meet it, with a shadow that moves across.
*/
function Flap({ value }: { value: string }) {
const [cards, setCards] = useState({ now: value, was: value, n: 0 });
// Remember the previous value while rendering, so the old card can fall away.
if (cards.now !== value)
setCards({ now: value, was: cards.now, n: cards.n + 1 });
const { now, was, n } = cards;
return (
<span className="gu-flip__card" aria-hidden="true">
<span className="gu-flip__half gu-flip__half--top">
<span>{now}</span>
</span>
<span className="gu-flip__half gu-flip__half--bottom">
<span>{n ? was : now}</span>
</span>
{n > 0 && (
<span key={n} className="gu-flip__fall">
<span className="gu-flip__half gu-flip__half--top gu-flip__leaf-top">
<span>{was}</span>
</span>
<span className="gu-flip__half gu-flip__half--bottom gu-flip__leaf-bottom">
<span>{now}</span>
</span>
</span>
)}
</span>
);
}
const pad = (n: number) => String(n).padStart(2, "0");
/**
* FlipClock: a split-flap countdown, like an old station board.
* - Every digit flips on its own with a real two-part fold, and the cards rattle as they settle.
* - Seconds tick with a soft glow on the colon; at zero the board flashes and shows the done message.
*/
export function FlipClock({
seconds,
title = "Doors open in",
done = "We are live",
theme = "dark",
}: {
/** How many seconds to count down from. */
seconds: number;
title?: string;
done?: string;
theme?: "light" | "dark";
}) {
const [left, setLeft] = useState(seconds);
useEffect(() => {
const end = Date.now() + seconds * 1000;
const id = window.setInterval(() => {
setLeft(Math.max(0, Math.round((end - Date.now()) / 1000)));
}, 250);
return () => window.clearInterval(id);
}, [seconds]);
const d = Math.floor(left / 86400);
const h = Math.floor((left % 86400) / 3600);
const m = Math.floor((left % 3600) / 60);
const s = left % 60;
const groups = [
{ label: "Days", v: pad(d) },
{ label: "Hours", v: pad(h) },
{ label: "Minutes", v: pad(m) },
{ label: "Seconds", v: pad(s) },
];
return (
<section
className="gu-flip"
data-theme={theme}
data-done={left === 0}
aria-label={title}
>
<h3 className="gu-flip__title">{left === 0 ? done : title}</h3>
<div className="gu-flip__board">
{groups.map((g, i) => (
<div
key={g.label}
className="gu-flip__group"
style={{ "--g": i } as CSSProperties}
>
<div className="gu-flip__pair">
{g.v.split("").map((ch, j) => (
<Flap key={j} value={ch} />
))}
</div>
<span className="gu-flip__label">{g.label}</span>
{i < 3 && (
<span
className="gu-flip__colon"
data-tick={s % 2}
aria-hidden="true"
/>
)}
</div>
))}
</div>
<p className="gu-flip__sr">
{d} days, {h} hours and {m} minutes left
</p>
</section>
);
}
Paste this into ChatGPT, Claude, Cursor, v0, Lovable or Bolt. It describes the layout, motion, colors and accessibility and includes the code, so the AI can rebuild it in any framework.
# Build this UI piece: Split-flap countdown
You are a senior front-end engineer. Recreate the piece below in my project. If I don't say which framework I use, ask once, then build it in that framework (React, Vue, Svelte, Angular, Astro, plain HTML/CSS/JS or anything else). Keep the behavior, motion, colors, spacing and accessibility exactly as described. Keep the code clean and commented for beginners.
## What it is
A countdown made of split-flap cards, like an old airport or station board. Days, hours, minutes and seconds each have two cards; whenever a digit changes, its card folds over in two parts with shadows moving across, and the orange colon dots pulse with the seconds. At zero the title changes and the board flashes twice.
## Layout and look
- Centred: a 18–24px bold title, then four groups with a 12px label under each ("Days", "Hours", ...).
- Card height clamp(64px, 12vw, 112px), width 0.7 × height, radius 10px, digits at 78% of the height, weight 800, tabular numbers, cream #f3eee3. Card colour: a subtle vertical gradient from #26262c to #1c1c21 (on light pages a darker #1d1d22 to #0e0e10), drop shadow below.
- A dark 2px hinge line across the middle and two small pins sticking out each side.
- Orange #ff5a1f colon dots between groups (hidden under 560px where groups wrap).
## Behavior and motion
1. Each card is made of a top half and a bottom half (overflow hidden; the bottom half's text is shifted up 50%).
2. On change, keep the previous value. Static layers: new value on top, old value on the bottom. A falling layer adds the old top half rotating rotateX 0 → −90° (275ms, ease-in, darkening to 50%) and then the new bottom half rotating 90° → 0 (330ms, overshoot cubic-bezier(0.3,1.6,0.5,1), starting lit-dark and brightening). perspective 600px on the pair.
3. Groups tilt in on load (rotateX −40°, 20px up, 90ms apart).
4. The colon is bright with a glow on odd seconds and dimmed to 35% on even seconds.
5. Time is computed from an end timestamp every 250ms, so it never drifts.
## Accessibility
- The section is labelled by the title; the cards are aria-hidden and a visually hidden sentence says "2 days, 7 hours and 42 minutes left" (minutes, so it is not noisy every second).
- prefers-reduced-motion: no fold, no tilt-in, no flash.
## Props
seconds (count down from), title, done (message at zero), theme.
## Reference implementation
The original is written in React with one plain CSS file. Dependencies: none (plain React and CSS). Translate it faithfully; do not add new libraries unless my framework needs them.
### FlipClock.tsx
```tsx
"use client";
import { useEffect, useState, type CSSProperties } from "react";
import "./flip-clock.css";
/**
* One split-flap digit. When the value changes, the top half of the old card falls forward
* and the bottom half of the new card swings down to meet it, with a shadow that moves across.
*/
function Flap({ value }: { value: string }) {
const [cards, setCards] = useState({ now: value, was: value, n: 0 });
// Remember the previous value while rendering, so the old card can fall away.
if (cards.now !== value)
setCards({ now: value, was: cards.now, n: cards.n + 1 });
const { now, was, n } = cards;
return (
<span className="gu-flip__card" aria-hidden="true">
<span className="gu-flip__half gu-flip__half--top">
<span>{now}</span>
</span>
<span className="gu-flip__half gu-flip__half--bottom">
<span>{n ? was : now}</span>
</span>
{n > 0 && (
<span key={n} className="gu-flip__fall">
<span className="gu-flip__half gu-flip__half--top gu-flip__leaf-top">
<span>{was}</span>
</span>
<span className="gu-flip__half gu-flip__half--bottom gu-flip__leaf-bottom">
<span>{now}</span>
</span>
</span>
)}
</span>
);
}
const pad = (n: number) => String(n).padStart(2, "0");
/**
* FlipClock: a split-flap countdown, like an old station board.
* - Every digit flips on its own with a real two-part fold, and the cards rattle as they settle.
* - Seconds tick with a soft glow on the colon; at zero the board flashes and shows the done message.
*/
export function FlipClock({
seconds,
title = "Doors open in",
done = "We are live",
theme = "dark",
}: {
/** How many seconds to count down from. */
seconds: number;
title?: string;
done?: string;
theme?: "light" | "dark";
}) {
const [left, setLeft] = useState(seconds);
useEffect(() => {
const end = Date.now() + seconds * 1000;
const id = window.setInterval(() => {
setLeft(Math.max(0, Math.round((end - Date.now()) / 1000)));
}, 250);
return () => window.clearInterval(id);
}, [seconds]);
const d = Math.floor(left / 86400);
const h = Math.floor((left % 86400) / 3600);
const m = Math.floor((left % 3600) / 60);
const s = left % 60;
const groups = [
{ label: "Days", v: pad(d) },
{ label: "Hours", v: pad(h) },
{ label: "Minutes", v: pad(m) },
{ label: "Seconds", v: pad(s) },
];
return (
<section
className="gu-flip"
data-theme={theme}
data-done={left === 0}
aria-label={title}
>
<h3 className="gu-flip__title">{left === 0 ? done : title}</h3>
<div className="gu-flip__board">
{groups.map((g, i) => (
<div
key={g.label}
className="gu-flip__group"
style={{ "--g": i } as CSSProperties}
>
<div className="gu-flip__pair">
{g.v.split("").map((ch, j) => (
<Flap key={j} value={ch} />
))}
</div>
<span className="gu-flip__label">{g.label}</span>
{i < 3 && (
<span
className="gu-flip__colon"
data-tick={s % 2}
aria-hidden="true"
/>
)}
</div>
))}
</div>
<p className="gu-flip__sr">
{d} days, {h} hours and {m} minutes left
</p>
</section>
);
}
```
### flip-clock.css
```css
.gu-flip {
--card: #1c1c21;
--card-2: #26262c;
--digit: #f3eee3;
--ink: #f3eee3;
--h: clamp(64px, 12vw, 112px);
--w: calc(var(--h) * 0.7);
--flip: 0.55s;
display: grid;
justify-items: center;
gap: 22px;
padding: 32px 16px;
color: var(--ink);
font-family: ui-sans-serif, system-ui, sans-serif;
}
.gu-flip[data-theme="light"] {
--card: #0e0e10;
--card-2: #1d1d22;
--ink: #0e0e10;
}
.gu-flip__title {
margin: 0;
font-size: clamp(18px, 2.6vw, 24px);
font-weight: 700;
letter-spacing: -0.02em;
animation: gu-flip-title 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes gu-flip-title {
from {
opacity: 0;
translate: 0 8px;
}
}
.gu-flip__board {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: clamp(10px, 2.4vw, 22px);
}
.gu-flip__group {
position: relative;
display: grid;
justify-items: center;
gap: 10px;
animation: gu-flip-in 0.8s calc(var(--g) * 90ms) cubic-bezier(0.16, 1, 0.3, 1)
backwards;
}
@keyframes gu-flip-in {
from {
opacity: 0;
translate: 0 20px;
rotate: x -40deg;
}
}
.gu-flip__pair {
display: flex;
gap: 4px;
perspective: 600px;
}
.gu-flip__label {
font-size: 12px;
font-weight: 600;
opacity: 0.6;
}
/* ---------- One card ---------- */
.gu-flip__card {
position: relative;
display: block;
width: var(--w);
height: var(--h);
border-radius: 10px;
font-size: calc(var(--h) * 0.78);
font-weight: 800;
font-variant-numeric: tabular-nums;
line-height: var(--h);
color: var(--digit);
box-shadow: 0 14px 24px -14px rgb(0 0 0 / 0.7);
transform-style: preserve-3d;
}
.gu-flip__half {
position: absolute;
left: 0;
right: 0;
height: 50%;
overflow: hidden;
background: linear-gradient(var(--card-2), var(--card));
backface-visibility: hidden;
}
.gu-flip__half > span {
display: block;
text-align: center;
}
.gu-flip__half--top {
top: 0;
border-radius: 10px 10px 0 0;
transform-origin: 50% 100%;
}
.gu-flip__half--bottom {
bottom: 0;
border-radius: 0 0 10px 10px;
transform-origin: 50% 0;
background: linear-gradient(var(--card), var(--card-2));
}
.gu-flip__half--bottom > span {
translate: 0 -50%;
}
/* The hinge line and its two little pins. */
.gu-flip__card::after {
content: "";
position: absolute;
left: 0;
right: 0;
top: calc(50% - 1px);
height: 2px;
background: rgb(0 0 0 / 0.55);
z-index: 3;
}
.gu-flip__card::before {
content: "";
position: absolute;
left: -3px;
right: -3px;
top: calc(50% - 4px);
height: 8px;
border-radius: 3px;
background:
linear-gradient(#3a3a42, #222) left / 5px 100% no-repeat,
linear-gradient(#3a3a42, #222) right / 5px 100% no-repeat;
z-index: 4;
}
/* The fold: old top falls, then new bottom swings down. */
.gu-flip__fall {
position: absolute;
inset: 0;
transform-style: preserve-3d;
z-index: 2;
}
.gu-flip__leaf-top {
animation: gu-flip-top calc(var(--flip) * 0.5) ease-in forwards;
}
.gu-flip__leaf-top::after,
.gu-flip__leaf-bottom::after {
content: "";
position: absolute;
inset: 0;
background: #000;
opacity: 0;
}
.gu-flip__leaf-top::after {
animation: gu-flip-dark calc(var(--flip) * 0.5) ease-in forwards;
}
.gu-flip__leaf-bottom {
rotate: x 90deg;
animation: gu-flip-bottom calc(var(--flip) * 0.6) calc(var(--flip) * 0.5)
cubic-bezier(0.3, 1.6, 0.5, 1) forwards;
}
.gu-flip__leaf-bottom::after {
opacity: 0.45;
animation: gu-flip-light calc(var(--flip) * 0.5) calc(var(--flip) * 0.5)
ease-out forwards;
}
@keyframes gu-flip-top {
to {
rotate: x -90deg;
}
}
@keyframes gu-flip-bottom {
to {
rotate: x 0deg;
}
}
@keyframes gu-flip-dark {
to {
opacity: 0.5;
}
}
@keyframes gu-flip-light {
to {
opacity: 0;
}
}
/* The colon blinks with the seconds. */
.gu-flip__colon {
position: absolute;
right: calc(clamp(10px, 2.4vw, 22px) / -2 - 3px);
top: calc(var(--h) / 2 - 14px);
width: 6px;
height: 28px;
background:
radial-gradient(circle, #ff5a1f 2.6px, transparent 3.2px) top / 6px 6px
no-repeat,
radial-gradient(circle, #ff5a1f 2.6px, transparent 3.2px) bottom / 6px 6px
no-repeat;
transition:
opacity 0.3s,
filter 0.3s;
}
.gu-flip__colon[data-tick="0"] {
opacity: 0.35;
}
.gu-flip__colon[data-tick="1"] {
filter: drop-shadow(0 0 4px #ff5a1f);
}
@media (max-width: 560px) {
.gu-flip__colon {
display: none;
}
}
.gu-flip[data-done="true"] .gu-flip__board {
animation: gu-flip-flash 0.9s 2;
}
.gu-flip[data-done="true"] .gu-flip__title {
color: #ff5a1f;
}
@keyframes gu-flip-flash {
50% {
filter: brightness(1.6) drop-shadow(0 0 18px rgb(255 90 31 / 0.6));
}
}
.gu-flip__sr {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip-path: inset(50%);
}
@media (prefers-reduced-motion: reduce) {
.gu-flip__fall {
display: none;
}
.gu-flip__group,
.gu-flip__title,
.gu-flip[data-done="true"] .gu-flip__board {
animation: none;
}
}
```
You might also want
Next piece: Tear-off ticket call to actionOdometer counter
Animations, beginner
Orbit loader
Animations, beginner
Aurora background
Animations, beginner