What are the 12 principles of animation, and how do I use them in code?
Disney animators Frank Thomas and Ollie Johnston set out the 12 principles of animation in "The Illusion of Life" (1981). Most of them map to CSS. Below is each principle with its code equivalent, plus a bouncing-ball example that combines several.
Steps
- The principles: Squash and Stretch, Anticipation, Staging, Straight Ahead and Pose to Pose, Follow Through and Overlapping Action, Slow In and Slow Out, Arc, Secondary Action, Timing, Exaggeration, Solid Drawing, Appeal.
- What they look like in CSS: Squash and Stretch = scale with different values per axis. Anticipation = a small reverse step at the start of @keyframes. Slow In/Out = animation-timing-function. Arc = x and y moving with different timings. Follow Through = a small overshoot then settle in the last keyframes. Timing = animation-duration. Exaggeration = bigger scale and translate values. Secondary Action = a light second motion on another element.
- Try the ball example: anticipation (it dips and squashes), jump (it stretches), top of the arc, landing (it squashes), then a small rebound.
- Use transform-origin: bottom so the squash happens from the contact point with the ground.
- Exaggerate with care. Let the motion serve the meaning, and respect prefers-reduced-motion by stopping repeating motion.
Sources
- Reference: Frank Thomas and Ollie Johnston, The Illusion of Life: Disney Animation (1981). Overview: https://en.wikipedia.org/wiki/Twelve_basic_principles_of_animation
The code
HTML
<!doctype html>
<html lang="ar" dir="rtl">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Bouncing ball: animation principles</title>
<style>
body { font-family: system-ui, "Segoe UI", Tahoma, sans-serif; display: grid; place-items: center; min-height: 100vh; margin: 0; gap: 1rem; }
.stage { position: relative; inline-size: 260px; block-size: 200px; border-block-end: 3px solid #555; }
/* x motion (arc, slow in/out) and y motion (bounce) use different timings */
.x { position: absolute; inset-block-end: 0; inset-inline-start: 0; animation: x 2.4s ease-in-out infinite alternate; }
.ball { inline-size: 40px; block-size: 40px; border-radius: 50%; background: #e17055; transform-origin: bottom;
animation: y 1.2s infinite; }
.shadow { position: absolute; inset-block-end: -8px; inline-size: 40px; block-size: 8px; border-radius: 50%; background: rgba(0,0,0,.25);
animation: sh 1.2s infinite; } /* secondary action */
@keyframes x { to { transform: translateX(200px); } }
[dir="rtl"] .x { animation-name: xr; }
@keyframes xr { to { transform: translateX(-200px); } }
@keyframes y {
0% { transform: translateY(0) scale(1, 1); animation-timing-function: ease-out; }
10% { transform: translateY(6px) scale(1.15, .8); animation-timing-function: ease-out; } /* anticipation: dip and squash */
40% { transform: translateY(-120px) scale(.9, 1.15); animation-timing-function: ease-in; } /* stretch in the air */
75% { transform: translateY(0) scale(1.2, .75); animation-timing-function: ease-out; } /* landing squash */
88% { transform: translateY(-14px) scale(.97, 1.04); animation-timing-function: ease-in; } /* small rebound */
100% { transform: translateY(0) scale(1, 1); }
}
@keyframes sh { 0%,75%,100% { transform: scaleX(1); opacity: .25; } 40% { transform: scaleX(.5); opacity: .1; } }
@media (prefers-reduced-motion: reduce) { .x, .ball, .shadow { animation: none; } }
</style>
<div class="stage" role="img" aria-label="كرة ترتد وتنضغط عند الهبوط">
<div class="x"><div class="shadow"></div><div class="ball"></div></div>
</div>
<script>
// Same page works in LTR: only the direction attribute changes the horizontal sign.
document.documentElement.addEventListener("dblclick", () => {
document.documentElement.dir = document.documentElement.dir === "rtl" ? "ltr" : "rtl";
});
</script>
</html>Related categories: Lottie & Icons · Kinetic Typography