AI CSS Animations

Page Flip Animation

A page lifts off the right of an open book and turns over to the left, on repeat. The leaf pivots on its left edge with rotateY, and its two faces are pseudo-elements with backface-visibility: hidden.

Also known as: css page flip animation, book page turn css, flip book animation css.

HTML

<div class="kfa-page-flip"><div class="kfa-page-flip-leaf"></div></div>

CSS

.kfa-page-flip {
  --c: var(--kfa-color, #3b82f6);
  font-size: var(--kfa-size, 16px);
  --paper: color-mix(in srgb, var(--c) 8%, #fff);
  --lines: repeating-linear-gradient(color-mix(in srgb, var(--c) 38%, transparent) 0 0.2em, transparent 0 0.6em) content-box;
  position: relative;
  display: flex;
  width: 10em;
  height: 6.4em;
  perspective: 26em;
  filter: drop-shadow(0 0.5em 0.6em color-mix(in srgb, var(--c) 35%, transparent));
}
/* the two pages that stay put, and both faces of the turning leaf */
.kfa-page-flip::before,
.kfa-page-flip::after,
.kfa-page-flip-leaf::before,
.kfa-page-flip-leaf::after {
  content: "";
  box-sizing: border-box;
  width: 5em;
  height: 100%;
  padding: 0.9em 0.75em;
}
.kfa-page-flip::before,
.kfa-page-flip-leaf::after {
  border-radius: 0.4em 0 0 0.4em;
  background: var(--lines), linear-gradient(270deg, rgb(0 0 0 / 0.1), transparent 30%), var(--paper);
}
.kfa-page-flip::after,
.kfa-page-flip-leaf::before {
  border-radius: 0 0.4em 0.4em 0;
  background: var(--lines), linear-gradient(90deg, rgb(0 0 0 / 0.1), transparent 30%), var(--paper);
}
.kfa-page-flip-leaf {
  position: absolute;
  top: 0;
  left: 50%;
  width: 5em;
  height: 100%;
  transform-origin: 0 50%;
  transform-style: preserve-3d;
  animation: kfa-page-flip-turn 2.8s cubic-bezier(0.45, 0.05, 0.3, 1) infinite;
}
.kfa-page-flip-leaf::before,
.kfa-page-flip-leaf::after {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
}
.kfa-page-flip-leaf::after {
  transform: rotateY(180deg);
}
@keyframes kfa-page-flip-turn {
  0%, 12% { transform: rotateY(0); }
  60%, 100% { transform: rotateY(-180deg); }
}

@media (prefers-reduced-motion: reduce) {
  .kfa-page-flip, .kfa-page-flip *, .kfa-page-flip::before, .kfa-page-flip::after, .kfa-page-flip *::before, .kfa-page-flip *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

Customizing this snippet

  • Color: set --kfa-color on the element or a parent. Currently previewing #3b82f6.
  • Base size: set --kfa-size. Every other dimension is in em, so the whole thing scales together. Currently previewing 16px.
  • Speed: change the duration on the transition or animation shorthand. Staggered delays are relative, so they keep their rhythm.
  • Reduced motion: the rule at the end of the CSS turns the motion off for people who asked their OS for less of it. Keep it.

Similar keyframe animations