Episode 1 — Fundamentals / 1.12 — CSS Animations and Motion Design

1.12 — CSS Animations & Motion Design: Quick Revision

Compact cheat sheet. Print-friendly.

How to use this material (instructions)

  1. Skim top-to-bottom in one pass before interviews or exams.
  2. If a row feels fuzzy — reopen the matching lesson: README.md1.12.a1.12.e.
  3. Drills1.12-Exercise-Questions.md.
  4. Polished answers1.12-Interview-Questions.md.

1.12.a CSS Transitions

Shorthand

transition: property duration timing-function delay;
transition: transform 300ms ease-out 0s;

Sub-properties

PropertyDefaultNotes
transition-propertyallPrefer listing explicitly
transition-duration0s0s = instant (no animation)
transition-timing-functioneaseKeywords or cubic-bezier()
transition-delay0sNegative values start partway

Timing functions

KeywordCubic-bezierFeel
ease(0.25, 0.1, 0.25, 1.0)General purpose
linear(0, 0, 1, 1)Constant speed
ease-in(0.42, 0, 1, 1)Slow → fast (exiting)
ease-out(0, 0, 0.58, 1)Fast → slow (entering)
ease-in-out(0.42, 0, 0.58, 1)Slow → fast → slow

Duration guide

RangePerceptionUse
100–200 msInstantColor change, icon swap
200–300 msResponsiveButtons, tooltips
300–500 msSmoothPanels, modals
> 500 msSlowDramatic reveals only

JS events

transitionruntransitionstarttransitionend (or transitioncancel)


1.12.b CSS Transform

Transform functions

FunctionWhat it doesExample
translateX(v) / translateY(v)Move on one axistranslateX(50px)
translate(x, y)Move on both axestranslate(10px, 20px)
scale(f) / scale(x, y)Resizescale(1.2)
rotate(angle)Spin (clockwise = positive)rotate(45deg)
skewX(a) / skewY(a)ShearskewX(-5deg)

Key rules

  • Transforms are visual only — no layout reflow.
  • Order matters: rotate translate ≠ translate rotate.
  • Default transform-origin: 50% 50% (center).
  • % in translate = relative to element's own size.

Centering trick

position: absolute;
top: 50%; left: 50%;
transform: translate(-50%, -50%);

1.12.c 3D Transforms

Perspective

MethodScope
perspective: 800px (parent)Shared vanishing point
transform: perspective(800px) …Per-element vanishing point

Small value = extreme depth. Large value = subtle depth.

3D functions

FunctionAxis
rotateX(a)Tips forward/back
rotateY(a)Turns left/right
rotateZ(a)Same as 2D rotate()
translateZ(v)Toward/away from viewer

Essential properties

PropertyPurpose
transform-style: preserve-3dChildren live in 3D space
backface-visibility: hiddenHide element when facing away
perspective-originMove vanishing point

Card-flip recipe

Parent:     perspective: 600px
Wrapper:    preserve-3d; transition: transform 600ms
Front:      backface-visibility: hidden
Back:       backface-visibility: hidden; rotateY(180deg)
Hover:      wrapper rotateY(180deg)

1.12.d Keyframe Animations

Syntax

@keyframes name {
  0%   { /* start */ }
  50%  { /* midpoint */ }
  100% { /* end */ }
}

.el { animation: name 500ms ease-out 0s 1 normal forwards running; }

Sub-properties

PropertyValues
animation-nameCustom name
animation-durationTime
animation-timing-functionSame as transition
animation-delayTime (negative = start partway)
animation-iteration-countNumber or infinite
animation-directionnormal · reverse · alternate · alternate-reverse
animation-fill-modenone · forwards · backwards · both
animation-play-staterunning · paused

Fill-mode quick reference

ValueDuring delayAfter end
noneOwn stylesSnaps back
forwardsOwn stylesKeeps to
backwardsApplies fromSnaps back
bothApplies fromKeeps to

Common patterns

/* Spinner */
@keyframes spin { to { transform: rotate(360deg); } }
.loader { animation: spin 0.8s linear infinite; }

/* Fade-in */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* Pulse */
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.05); }
}

JS events

animationstartanimationiterationanimationend (or animationcancel)


1.12.e Animation Performance

The rendering pipeline cost

  Property animated        Stages triggered
  ────────────────────     ───────────────────────
  width / height / top     Layout → Paint → Composite  (expensive)
  color / box-shadow       Paint → Composite            (moderate)
  transform / opacity      Composite only               (cheap ✓)

Frame budget

60 fps = 1000ms / 60 = 16.67 ms per frame

will-change rules

DoDon't
Apply to elements about to animate* { will-change: transform; }
Remove after animation endsLeave on permanently
Measure first, optimize secondUse as a magic fix

GPU memory per layer

width × height × devicePixelRatio² × 4 bytes
Example: 300×200 @2x = 600×400×4 = 960 KB

Animatable vs non-animatable properties

Animatable (safe)Animatable (expensive)NOT animatable
transformwidth, heightdisplay
opacitymargin, paddingfont-family
colortop, left, right, bottomposition (keyword)
background-colorborder-widthfloat
border-colorfont-sizeoverflow (keyword)
border-radiusbox-shadowgrid-template-*

Performance checklist

  1. Animate transform + opacity only
  2. Convert top/lefttranslateX/Y
  3. Convert size animations → scale()
  4. Animate shadows via pseudo-element opacity
  5. Use will-change sparingly
  6. Respect prefers-reduced-motion
  7. Pause off-screen infinite animations
  8. Test on low-end devices (CPU throttle 4×)

prefers-reduced-motion template

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

Quick formulas

Frame budget:         1000 ÷ 60 = 16.67 ms
GPU layer memory:     W × H × DPR² × 4 bytes
Transition events:    one transitionend per animated property
Animation events:     one animationend per animation name

Full lessons → README.md · Drills → 1.12-Exercise-Questions.md · Interviews → 1.12-Interview-Questions.md