An airport-style split-flap board. Click it and each letter rolls forward, flap by flap, to the next month.

reacttypescriptcss
January

click or tap the board for the next month

It works the same on phones: tap the board for the next month, or use the arrows below it. With the keyboard, Tab to the board and press Enter or Space for the next month, or ← → to go either way. Screen readers hear the full month name, not three letters. If your device is set to reduce motion, the letters change straight away without rolling.

The idea

Calendars are usually flat. This one clatters: every month change is a little mechanical moment, like a departures board at an airport updating, letter by letter.

Words you'll see 14
component
A reusable piece of interface, like a component in Figma. MonthFlap is one, built from FlapBoard and FlapSlot.
props
The settings you hand to a component, like start or colors. Change them and the board changes.
.tsx (TypeScript)
The file type here: interface code written in TypeScript, which is JavaScript that also checks what kind of value each setting expects.
state (useState)
Something a component remembers, like the month or the letter on a tile. When it changes, what you see updates.
useEffect
Code that runs after something changes, here to start the next flap. It can clean up after itself, like cancelling a timer.
useRef
A way to remember a value without redrawing anything, here whether a slot is mid-roll.
setTimeout
Runs something once, after a wait in milliseconds. Each flap is one.
overflow: hidden
Hides anything that spills outside a box, like clip content in Figma.
@keyframes
A named animation: what something looks like at the start, the end, and anywhere between.
rotateX
Tips something forwards or backwards, like a flap folding down.
transform-origin
The point something turns around, like moving the pivot point in Figma. Here, the hinge.
perspective
Adds depth, so a 3D fold looks real instead of flat.
prefers-reduced-motion
A device setting for people who find movement uncomfortable. Code can check it and calm things down.
aria-label
A name read out by screen readers, for when what's on screen isn't clear on its own.

How it works

Point at a step, tap it or Tab to it, to light up its lines in the code.

  1. 01

    Split in half

    Every letter tile is really two halves stacked, so the top half can fold down on its own.

    1. Each half is a box half as tall as the tile, and it hides whatever spills out of it (overflow: hidden). Like a frame with clip content on in Figma.
    2. Inside, the full letter is twice as tall as the half. The bottom half shifts it up, so it shows the lower part of the letter.
    3. At the back: the new letter's top half waits, and the old letter's bottom half stays until it gets covered.
    4. At the front: the old top half folds down until it's flat, then the new bottom half swings up into place. Each fold is a tiny animation that turns it 90° (@keyframes with rotateX), hinged on the middle line (transform-origin).
    5. A sense of depth (perspective) makes the folding flaps look like they tip towards you.
    MonthFlap.tsx
    const flapCss = `
    @keyframes flapTopFold { from { transform: rotateX(0deg) } to { transform: rotateX(-90deg) } }
    @keyframes flapBottomOpen { from { transform: rotateX(90deg) } to { transform: rotateX(0deg) } }
    `
    
    // …
    
    // each half only shows its half of the letter: the box is half height and hides the rest
    <div style={{
      position: 'absolute',
      left: 0,
      right: 0,
      height: '50%',
      [half]: 0,
      overflow: 'hidden',
      background: colors.tile,
      borderRadius: half === 'top' ? '8px 8px 0 0' : '0 0 8px 8px',
      backfaceVisibility: 'hidden',
      ...style,
    }}>
      <span style={{
        position: 'absolute',
        left: 0,
        right: 0,
        height: '200%', // the full letter, twice this half's height
        top: half === 'top' ? 0 : '-100%', // the bottom half shows the lower part of the letter
        display: 'flex',
        alignItems: 'center',
        justifyContent: 'center',
      }}>
        {char}
      </span>
    </div>
    
    // …
    
    perspective: 400, // gives the folding flaps depth
    
    // …
    
    {/* back layers: the new letter's top waits behind, the old letter's bottom stays until covered */}
    <Half char={flipping ? next! : shown} half="top" colors={colors} />
    <Half char={shown} half="bottom" colors={colors} />
    
    {/* front layers, only while flipping: the old top folds down, then the new bottom swings into place */}
    {flipping && (
      <>
        <Half char={shown} half="top" colors={colors} style={{ transformOrigin: 'bottom', animation: `flapTopFold ${half} ease-in forwards`, zIndex: 2 }} />
        <Half char={next!} half="bottom" colors={colors} style={{ transformOrigin: 'top', transform: 'rotateX(90deg)', animation: `flapBottomOpen ${half} ease-out ${half} forwards`, zIndex: 2 }} />
      </>
    )}

    This is part of the file. Copy the complete file from the Code tab.

  2. 02

    Rolling through letters

    Like a real board, a slot can only move forward, so J to F rolls all the way round through K, L, M… Z, A.

    1. Each slot remembers the letter it shows now, and the letter it's flipping to (useState).
    2. Each flap moves one step along the alphabet, and after Z it wraps back round to the blank.
    3. After one flap (70 milliseconds) it lands on the new letter, and if that isn't the target yet, it flaps again (setTimeout inside useEffect).
    4. The three slots start 60ms apart, so the letters settle one after another instead of all at once.
    5. If your device is set to reduce motion (prefers-reduced-motion), the letter simply changes, with no rolling.
    MonthFlap.tsx
    // Every slot can only roll forward through this list, like a real airport board.
    const CHARS = ' ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    const nextChar = (c: string) => CHARS[(CHARS.indexOf(c) + 1) % CHARS.length]
    
    // …
    
    const [shown, setShown] = useState(target) // letter on the tile now
    const [next, setNext] = useState<string | null>(null) // letter it's flipping to, while a flap runs
    const rolling = useRef(false) // true between the first flap of a change and landing on the target
    
    useEffect(() => {
      if (shown === target) {
        rolling.current = false
        return
      }
      const still = window.matchMedia('(prefers-reduced-motion: reduce)').matches
      if (still) {
        setShown(target) // no rolling: the letter simply changes
        return
      }
      // one flap: show the next letter along, then land on it and go again until we reach the target.
      // Only the first flap of a change waits for this slot's delay.
      const wait = rolling.current ? 0 : delay
      rolling.current = true
      const start = setTimeout(() => {
        setNext(nextChar(shown))
        onFlap?.()
      }, wait)
      return () => clearTimeout(start)
    }, [shown, target]) // eslint-disable-line react-hooks/exhaustive-deps
    
    useEffect(() => {
      if (next === null) return
      const land = setTimeout(() => {
        setShown(next)
        setNext(null)
      }, flapMs)
      return () => clearTimeout(land)
    }, [next, flapMs])
    
    // …
    
    // slots start 60ms apart, so the letters settle one after another
    <FlapSlot key={i} target={c} delay={i * 60} colors={colors} onFlap={onFlap} />

    This is part of the file. Copy the complete file from the Code tab.

  3. 03

    Changing the month

    The whole board is one button: click for the next month, or use the arrows and ← → keys.

    1. One number remembers the month: 0 is January, 11 is December. Stepping wraps round, so December goes back to January (% 12, the remainder after dividing by 12).
    2. The board is a real button, so clicking, Enter and Space all flip it. The page also listens for the ← → keys (keydown event) to go either way.
    3. Screen readers hear the full month name instead of three letters (aria-label), and the tiles themselves are hidden from them (aria-hidden).
    MonthFlap.tsx
    const [month, setMonth] = useState(start)
    const go = (step: number) => setMonth((m) => (m + step + 12) % 12) // wraps DEC → JAN
    
    // …
    
    {/* the whole board is one button: click for the next month, ← → keys go either way */}
    <button
      ref={boardRef}
      type="button"
      onClick={() => go(1)}
      onKeyDown={(e) => {
        if (e.key === 'ArrowRight') { e.preventDefault(); go(1) }
        if (e.key === 'ArrowLeft') { e.preventDefault(); go(-1) }
      }}
      aria-label={`${MONTH_NAMES[month]}. Next month`}
      style={{ border: 0, padding: 0, background: 'none', cursor: 'pointer', borderRadius: 18 }}
    >
      <span aria-hidden="true">
        <FlapBoard word={MONTHS[month]} colors={colors} onFlap={onFlap} />
      </span>
    </button>

    This is part of the file. Copy the complete file from the Code tab.

Use it

Try it here first

Nothing to install. Open the Edit tab, change the code, and watch the preview update as you type.

When you want it in your own project

The buttons above copy the complete files. The code in How it works is only excerpts, so copy from here.

  1. You need Node.js installed. In a terminal, run npx create-next-app@latest my-month-flap --yes to make a new Next.js project, then cd my-month-flap.
  2. Inside the app folder, make a folder called components. Copy the complete file with the button above and save it as app/components/MonthFlap.tsx.
  3. Open app/page.tsx, delete everything in it, and paste the example below.
  4. Run npm run dev and open localhost:3000. Click the board.
  5. Change these first: the month it opens on (start, where 0 is January and 11 is December) and the colours (colors). To spell any word instead of a month, use FlapBoard with word="HELLO".
app/page.tsx
import MonthFlap from './components/MonthFlap'

export default function Page() {
  return (
    <main style={{ background: '#FFF8E5', minHeight: '100vh', display: 'grid', placeItems: 'center' }}>
      <MonthFlap
        start={8} // opens on SEP: 0 is January, 11 is December
        colors={{ frame: '#3336A3', rim: '#262986', tile: '#FFF8E5', ink: '#1a1a1a' }}
      />
    </main>
  )
}
What you can change 13
<MonthFlap /> 3
startoptional
The month it opens on: 0 is January, 11 is December. Default 0.
colorsoptional
The board colours. Give all four parts, listed below.
onFlapoptional
Something to do on every flap, like playing a tick sound. It's a function, so it only works inside a file that starts with 'use client'.
Inside colors 4
framerequired
The outer frame, and the arrows and month name below. Default #3336A3.
rimrequired
The darker strip the tiles sit in. Default #262986.
tilerequired
The letter tiles. Default #FFF8E5.
inkrequired
The letters. Default #1a1a1a.
<FlapBoard /> (any word) 3
wordrequired
The word to spell, in capitals, like HELLO. Change it and every slot rolls to its new letter.
colorsoptional
The same four colours as above.
onFlapoptional
Something to do on every flap.
<FlapSlot /> (one letter) 3
targetrequired
The letter this slot rolls to.
flapMsoptional
How long one flap takes, in milliseconds. Default 70. Try 300 to watch it in slow motion.
delayoptional
How long this slot waits before it starts rolling, in milliseconds. Default 0.
Dependencies 4
  • React 18+useState, useEffect and useRef. Nothing else to install.
  • No animation libraryEach flap is two small CSS keyframe animations.
  • Montserrat BlackOptional font for the letters (Montserrat, weight 900), read from --font-montserrat. Falls back to the system sans-serif.
  • Sound (optional)Pass onFlap to play a sound per flap. The demo uses cuelume's tick, at most one every 70ms.
Things to learn next 7