Flipbook Codepen May 2026
The magic happens here. We use preserve-3d to keep the 3D context and rotateY to turn the pages.
/* Layout setup */
body
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background: #f0f0f0;
font-family: sans-serif;
.scene
width: 300px;
height: 400px;
perspective: 1000px; /* Depth of field */
.book
width: 100%;
height: 100%;
position: relative;
transform-style: preserve-3d;
.page
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
cursor: pointer;
/* The flip animation logic */
transform-style: preserve-3d;
transition: transform 0.8s cubic-bezier(0.645, 0.045, 0.355, 1);
transform-origin: left center; /* Hinge on the left */
/* Visuals */
box-shadow: 0 0 5px rgba(0,0,0,0.1);
/* Front and Back faces of a page */
.front, .back
position: absolute;
width: 100%;
height: 100%;
backface-visibility: hidden; /* Hide the back side when facing away */
display: flex;
justify-content: center;
align-items: center;
font-size: 1.5rem;
background: white;
border: 1px solid #ddd;
box-sizing: border-box;
.back
background: #fff;
transform: rotateY(180deg); /* The back is flipped by default */
/* Active state - this class is toggled by JS */
.page.flipped
transform: rotateY(-180deg);
/* Z-indexing so pages stack correctly */
/* We stack them in reverse order in HTML, or use z-index */
.page:nth-child(1) z-index: 4;
.page:nth-child(2) z-index: 3;
.page:nth-child(3) z-index: 2;
.page:nth-child(4) z-index: 1;
/* Helper styling */
.click-hint
position: absolute;
bottom: 20px;
font-size: 0.8rem;
color: gray;
Search tag: pure css flipbook codepen no js
These pens rely on HTML checkboxes (<input type="checkbox">) or :hover states. They are lightweight but require pre-defined page counts. You cannot drag the page; you click a "Next" button.
Best for: Mobile menus, product cards, short storybooks (2-6 pages).
CodePen is the perfect playground for flipbooks because:
A flipbook on CodePen isn’t just a nostalgic toy. It’s a lesson in state management, animation timing, and user interaction — all wrapped in retro charm. flipbook codepen
Example shadow style:
.page::before
content: "";
position: absolute; inset: 0;
background: linear-gradient(90deg, rgba(0,0,0,0.35), rgba(0,0,0,0));
pointer-events: none; opacity: var(--shadow, 0);
Animate --shadow with JS mapped to rotation angle.
Most pens utilize a strict naming convention:
<div class="flipbook">
<div class="page hard">Cover</div>
<div class="page">
<div class="front">Page 1</div>
<div class="back">Page 2</div>
</div>
<div class="page">
<div class="front">Page 3</div>
<div class="back">Page 4</div>
</div>
<div class="page hard">Back</div>
</div>
document.getElementById('prevBtn').addEventListener('click', () => currentFrame = (currentFrame - 1 + totalFrames) % totalFrames; drawFrame(currentFrame); );document.getElementById('nextBtn').addEventListener('click', () => currentFrame = (currentFrame + 1) % totalFrames; drawFrame(currentFrame); ); The magic happens here
document.getElementById('slider').addEventListener('input', (e) => currentFrame = parseInt(e.target.value); drawFrame(currentFrame); );
// Optional: Thumb-drag flip simulation (mouse drag) let isDragging = false; canvas.addEventListener('mousedown', (e) => isDragging = true; let startX = e.clientX; let startFrame = currentFrame;
function onMouseMove(moveEvent) if (!isDragging) return; let deltaX = moveEvent.clientX - startX; let frameDelta = Math.floor(deltaX / 15); // sensitivity let newFrame = startFrame + frameDelta; newFrame = ((newFrame % totalFrames) + totalFrames) % totalFrames; drawFrame(newFrame); currentFrame = newFrame;
function onMouseUp() isDragging = false; window.removeEventListener('mousemove', onMouseMove); window.removeEventListener('mouseup', onMouseUp); Search tag: pure css flipbook codepen no js
window.addEventListener('mousemove', onMouseMove); window.addEventListener('mouseup', onMouseUp); );
The "flip" happens via transform-style: preserve-3d. The container gets a perspective: 2000px; to create depth. As the user clicks, the page rotates along the Y-axis from 0deg to -180deg.