Loading content...
Loading content...
Master purposeful, smooth, and accessible animation for modern web applications. Learn how user interactions trigger state transitions, harness hardware-accelerated 2D transforms, fine-tune easing timing functions, orchestrate multi-step @keyframes timelines, coordinate JavaScript state with CSS visuals, and respect user motion preferences.
Visual change over time to provide intuitive feedback, visual continuity, and delight
In modern web development, animation is simply a visual change over time. Instead of elements abruptly appearing, disappearing, or snapping into new dimensions, animations cushion state transitions so users understand what just happened in the interface.
@keyframes (like a continuous loading spinner).The 4 core components of the transition shorthand property
A CSS transition tells the browser: "When this property changes value, don't change it instantlyβinterpolate it gradually over time."
Specifies which CSS property to animate (e.g. transform, opacity, background-color). Avoid animating all in production because it forces unnecessary browser performance checks.
How long the transition takes from start to finish (e.g. 200ms, 0.3s). Micro-interactions should typically stay between 150ms and 350ms to feel snappy.
Mathematical curve that controls acceleration and deceleration (e.g. ease, linear, ease-out).
Wait period before the transition starts (e.g. 50ms). Useful for staggering lists of cards or delayed tooltips.
The 3 primary high-performance transforms used in modern UI design
The CSS transform property alters the geometry of an element without disrupting other elements on the page. Because it does not trigger document layout reflows, transforms are the industry standard for smooth animations.
Moves elements along X (horizontal) or Y (vertical) axes without shifting surrounding DOM siblings.
Enlarges or shrinks elements proportionally from their center transform-origin.
Rotates elements clockwise (positive degrees) or counter-clockwise (negative degrees).
Visualizing the acceleration and deceleration differences between curves
Timing functions dictate how an animation's speed evolves from start to end. Real-world physical objects don't start or stop instantly at constant speedsβthey accelerate and decelerate.
Constant velocity. Best for progress bars & spinners.
Default curve. Starts slightly fast, slows gently at end.
Starts fast, cushions into destination. Ideal for UI entrances!
Sluggish start, accelerates fast. Best for UI exits.
Soft start, fast middle, soft finish. Great for loops.
Experiment with duration, timing functions, and transforms in real time
Orchestrating multi-stage autonomous animations across percentage milestones
While transitions simply connect two states (A β B), @keyframes allow you to define any number of intermediate steps throughout a timeline using percentages (0%, 25%, 50%, 100%) or the from and to keywords.
Once defined, you attach the keyframe sequence to any selector using animation-name and animation-duration.
The 6 core properties governing keyframe playback behavior
Matches the name declared after @keyframes <name>.
Total time taken to complete 1 full iteration (e.g. 2s, 500ms).
Easing applied between each keyframe milestone (e.g. ease-in-out).
Number of repetitions (e.g. 1, 3, or infinite for spinners).
Playback order: normal, reverse, or alternate (ping-pong effect).
forwards retains the 100% keyframe styles after playback finishes.
Configure 0%, 50%, and 100% milestone values and test live playback
How to choose the appropriate tool for any web development requirement
| Feature | CSS Transition | CSS Animation (@keyframes) |
|---|---|---|
| Number of States | 2 states (Initial state β Target state) | Infinite intermediate steps (0% through 100%) |
| Trigger Mechanism | Requires explicit state change (:hover, :focus, JS class) | Can run automatically on page load or on state change |
| Looping | No autonomous continuous loop | Full loop control (animation-iteration-count: infinite) |
| Reverse Behavior | Automatically reverses when hover/focus state ends | Requires explicit animation-direction: alternate |
| Primary Use Cases | Buttons, cards, accordion menus, toggle switches | Loading spinners, skeleton loaders, complex page banners |
The industry pattern: JavaScript toggles state classes; CSS executes smooth visuals
A common mistake junior full-stack developers make is trying to animate elements directly in JavaScript loops (like setInterval). The professional architecture divides labor cleanly:
Test the JS state change pipeline with configurable travel distance and speed
Diagnose and repair common CSS animation bugs found in production code
How do you fix this broken animation?
Five subtle, production-ready micro-interactions used across modern web apps
Hover or click on the UI patterns below to experience standard production micro-interactions:
Respecting vestibular sensitivities and user operating system motion preferences
Some users experience severe motion sickness, vertigo, or vestibular disorders when reading screens with large sliding, spinning, or scaling animations. Operating systems (Windows, macOS, iOS, Android) provide a setting called "Reduce Motion", which websites query using the prefers-reduced-motion media query.
Why animating transform & opacity maintains buttery 60 frames per second
Browsers render pages in three successive steps: Layout (Reflow) β Paint β Composite. Cheap animations only touch the final Composite stage.
Handled directly on the graphics card. Zero CPU layout reflows!
Forces the CPU to recompute the document coordinates of every sibling element on every frame.
Configure entrance motion, duration, easing, and accessible reduced-motion fallback
Goal: Build an animated notification card. When activated, it transitions from resting (opacity: 0, translateY: 20px) to active (opacity: 1, translateY: 0).
Pitfalls that degrade performance or user experience in web applications
Animating top or height causes CPU layout recalculations (reflow) on every frame. Always prefer transform: translate() and opacity.
If you define transition only inside :hover, the element will smoothly animate on mouse enter, but jerk and snap back immediately on mouse leave.
Animations over 500ms make user interfaces feel sluggish. Keep UI micro-interactions snappy (between 150ms and 300ms) with purposeful easing.
Unchecked motion triggers physical nausea and dizziness for users with vestibular sensitivities. Always provide a reduced-motion fallback.
Validate your mastery of transitions, transforms, timing functions, and accessibility
Test your mental model of CSS transitions, transforms, timing functions, keyframes, JavaScript coordination, and WCAG motion accessibility.
What is the fundamental architectural difference between a CSS Transition and a CSS Animation?
Core concepts and engineering habits you have mastered in this module