Flip Page
A plain sheet folds down over the screen from its left edge, the page changes underneath, then the sheet keeps turning and vanishes: the content does not rotate, it is replaced out of sight. 1.2 s, 3D CSS + 1.9 KB of JavaScript, two pages driven by a button.
Updated
This effect is part of Effect.Labs — 846 vanilla effects, some free, some premium. Transitions has 52 effects, including 9 free. Explore the category →
3 usage examples



How it works
The .flpg-screen (full width of its container, 200 px high, overflow: hidden) stacks the two .flpg-page elements and, on top, a .flpg-layer that takes no clicks. That layer holds a single sheet, .flpg-sheet: a rectangle the size of the screen, painted with a purple gradient, hinged on its left edge (transform-origin: left center). At rest it is edge-on (rotateY(-90deg)) and hidden.
A click on .flpg-btn starts the flpgFlip animation: the sheet leaves −90°, lies flat at 40% of the time (480 ms), stays there until 60% (720 ms), then heads to +90° and is no longer shown at 1.2 s. The script swaps the pages in the middle of that plateau, at 600 ms, by adding or removing .flpg-is-b on the screen: at that moment the sheet covers everything, so the swap cannot be seen. Because it travels from −90° to +90°, it never shows its back. Reading at 200 ms on a 568 px screen: the sheet, at −58°, already covers the left 311 px and overshoots the height (375 px for 200, the excess is clipped by the screen); the perspective is what enlarges it as it comes toward the eye.
That perspective is recomputed on every click: 1,000 px at least, 1.5 times the screen width beyond that (1,872 px read for a 1,248 px screen), so the sheet's free edge does not pass behind the viewpoint on a wide screen. One click goes to page B and stays there, the next returns to A; a click during the 1.2 s is ignored (two clicks 120 ms apart: a single transition). Every .flpg-stage has its own lock: with two copies on the same page, clicking the second leaves the first alone.
Accessibility
- Reduced motion: the script reads
prefers-reduced-motionagain on each click. When the preference is on, no sheet goes by: the class is swapped right away and the pages hand over in 150 ms of opacity (page B already in place 60 ms after the click, in the three engines tested). - Keyboard: the trigger is a real
<button>, Enter and Space turn the sheet. During the animation it getsaria-disabled="true"and dims, but it is not disabled: focus stays on it, so you can go again as soon as it ends without tabbing back. In Safari, Tab skips buttons unless "Press Tab to highlight each item" is checked; Option + Tab reaches it. - Screen readers: the hidden page is
visibility: hidden, so it is neither read nor reached; the sheet's layer isaria-hidden. However, nothing announces the change, and the button label is the same both ways: addaria-live="polite"on.flpg-screen, or a label that says where you are going. - Touch: a tap on the button is enough (181 × 40 px button in the demo). There is no drag gesture: the sheet does not follow the finger.
Browser compatibility
CSS (perspective on the parent, rotateY, backface-visibility doubled with its -webkit- prefix, @keyframes, inset) + 1.9 KB of dependency-free JavaScript. In Chromium 149 and Firefox 151 the sheet is drawn in true perspective (a trapezoid that grows as it comes, shrinks as it leaves). The WebKit 26.5 of our test bench swaps the pages and honors the lock, the keyboard and reduced motion, but draws the sheet flat, like a shutter that widens and then withdraws: that test engine flattens CSS 3D, and a real Safari was not checked. inset sets the floor: Chrome 87, Firefox 66, Safari 14.1.
Without JavaScript, page A stays on screen and the button does nothing: pair it with a link if page B is a real destination. In a browser without inset, write top, right, bottom and left at 0 on .flpg-page, .flpg-layer and .flpg-sheet.
The code
HTML structure to paste into your page (the CSS + JS come with your purchase):
<div class="flpg-stage">
<div class="flpg-screen">
<div class="flpg-page flpg-page-a">…</div>
<div class="flpg-page flpg-page-b">…</div>
<div class="flpg-layer" aria-hidden="true">
<div class="flpg-sheet"></div>
</div>
</div>
<button type="button" class="flpg-btn">…</button>
</div>
One-time payment, no subscription — the code is yours forever
Customize
Options passed to the API or data-* attributes:
| Option / property | Default | Effect |
|---|---|---|
Sheet color (CSS — .flpg-sheet { background }) |
#7c3aed → #4f46e5 gradient |
It is all you see in the middle of the transition. A brand color makes it a bold passage; page B's background color makes it almost invisible on arrival. |
Duration (CSS — animation: flpgFlip 1.2s; JS — SWAP_AT, END_AT) |
1.2 s; swap at 600 ms, end at 1,200 ms | The three values go together: SWAP_AT must fall inside the flat plateau (between 40% and 60% of the duration), otherwise the page is seen changing before the sheet has covered it. |
Hinge side (CSS — transform-origin on .flpg-sheet and the angles in @keyframes flpgFlip) |
left center, from −90° to +90° |
With right center and the angles reversed (90° at the start and at rest, −90° at the end), the sheet comes in from the right; variant checked in Chromium. |
Screen size (CSS — .flpg-screen { height }, container width) |
100% wide, 200 px high | The sheet always takes the screen's size and the script fits the perspective to its width: nothing else to tune, from a 72 px tile to a full page. |
Starting page (HTML — flpg-is-b class on .flpg-screen) |
absent: page A is shown | Written in the HTML, it makes the effect start on page B; the first click then returns to A. |
FAQ
.flpg-page-b if the screen lacks the flpg-is-b class, .flpg-page-a otherwise), then call the click. The sheet covers the screen during the swap: the reader sees a third page arrive, then a fourth..flpg-btn. Keep it in the HTML with the hidden attribute, then call stage.querySelector('.flpg-btn').click() from your code (timer, end of loading, click on a menu link). Checked: the hidden button does start the sheet; a call during a running transition is ignored.