TransitionsPremium

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.

CSSJS3DPerspective

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

Lunch menu to dinner menu — a neighborhood bistro's website — Flip Page example 1

① Lunch menu to dinner menu — a neighborhood bistro's website

WhenA customer planning a dinner lands on the lunch menu and presses "See the other service": a kraft-colored sheet folds down over the dishes, then uncovers the dinner menu on its bottle-green background.
WhyBoth menus share the same layout: with no cover, you would see prices jump from one line to the next. The sheet hides the swap and echoes the gesture of flipping a menu over.
Settings508 × 252 px screen, kraft gradient sheet (.flpg-sheet { background }), cream page A and bottle-green page B, pill button aligned right under the screen, with a label that works both ways. For the capture, the scene presses the button by itself.
Next paper after the grade — a French teacher's grading tool — Flip Page example 2

② Next paper after the grade — a French teacher's grading tool

WhenThe teacher has just given Lina's essay 14 out of 20 and presses "Save the grade": a white sheet passes over the paper, Tom's is underneath, and the grade and comments in the panel are empty.
WhyThe passing sheet confirms the grade is saved and separates two papers that look alike; the 1.2 s lock keeps a double click from saving twice.
Settings236 × 302 px screen on the left, white sheet, .flpg-btn placed at the bottom of the grading panel (position: absolute inside .flpg-stage). The paper counter and the grade follow the .flpg-is-b class through a MutationObserver that belongs to the scene; the effect itself only alternates between two pages.
"Days without an accident" counter — a boilermaking workshop's screen — Flip Page example 3

③ "Days without an accident" counter — a boilermaking workshop's screen

WhenAt midnight the workshop counter goes from 146 to 147 days: only the units tile is swept by a steel-gray sheet, and the 6 becomes a 7.
WhyOn a screen watched from a distance, a digit that changes in one go is missed; the sheet draws the eye for a second, on the only tile that moves.
SettingsA 72 × 104 px .flpg-stage for the units tile, pages A and B reduced to one digit, steel-gray sheet. The button stays in the HTML with the hidden attribute and the page's clock calls its click() (simulated in the capture). At this size the 1,000 px perspective nearly flattens the rotation: what you mostly see is a shutter.

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-motion again 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 gets aria-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 is aria-hidden. However, nothing announces the change, and the button label is the same both ways: add aria-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.

Chrome 87+✓ Full (measured in Chromium 149)
Firefox 66+✓ Full (measured in Firefox 151)
Safari 14.1+✓ Swap measured, depth not checked
Edge 87+✓ Full (Chromium engine)
Mobile iOS 14.5+✓ Not checked on a device
Android Chrome 87+✓ Full (emulated touch)

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):

index.html — structure
<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 / propertyDefaultEffect
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

In Page Turn, the content page itself turns: it swings on its binding and shows the next one, already underneath. It is a book object, the size of a page, that you click directly. Flip Page rotates no content: a plain sheet passes over a screen of any size, the swap happens hidden, and a separate button is in charge. Page Turn to leaf through a document, Flip Page to change views in an interface.
The code alternates between A and B, but the hidden page can change content between two clicks. Before starting, write what comes next into the one that is not shown (.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.
Yes, provided the button stays: the script exposes no function and only listens to the click on .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.