Lab 06: CSS Animations

Time: 30 minutes | Level: Practitioner | Docker: docker run -it --rm node:20-alpine sh

Overview

Master CSS animations from @keyframes to advanced techniques: the 8-property animation shorthand, transitions vs animations, will-change, motion path with offset-path, timing functions, and accessibility considerations.


Step 1: @keyframes

/* Basic keyframe definition */
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* With percentage steps */
@keyframes slideAndFade {
  0%   { opacity: 0; transform: translateY(-20px); }
  60%  { opacity: 1; transform: translateY(4px); }
  100% { opacity: 1; transform: translateY(0); }
}

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

/* Shimmer loading effect */
@keyframes shimmer {
  0%   { background-position: -1000px 0; }
  100% { background-position: 1000px 0; }
}

/* Typing cursor */
@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

/* Rotation */
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Bounce */
@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40%           { transform: translateY(-24px); }
  60%           { transform: translateY(-12px); }
}

Step 2: Animation Shorthand — 8 Sub-Properties

💡 animation-fill-mode: forwards is almost always what you want — it keeps the element at its final state after the animation ends.


Step 3: Transitions vs Animations

When to use which:

Scenario
Use

Hover/focus state change

Transition

Looping animation

Animation

Multi-step sequence

Animation

Playing on page load

Animation

Triggered by JS

Animation (toggle class)


Step 4: will-change


Step 5: CSS Motion Path (offset-path)


Step 6: Cubic-Bezier Timing Functions


Step 7: prefers-reduced-motion


Step 8: Capstone — Timing Function Calculator

📸 Verified Output:


Summary

Property
Key Values
Purpose

animation-name

@keyframes name

Which animation

animation-duration

0.3s, 500ms

How long

animation-timing-function

ease-out, cubic-bezier()

Speed curve

animation-delay

0.1s

Wait before start

animation-iteration-count

1, infinite

How many times

animation-direction

alternate, reverse

Forward/backward

animation-fill-mode

forwards, both

State after end

animation-play-state

paused, running

Pause/resume

will-change

transform, opacity

GPU layer hint

offset-path

path(...)

Motion along path

prefers-reduced-motion

reduce, no-preference

Accessibility

Last updated