Lab 10: Animations & Transitions

Objective

Create smooth, performant animations and transitions using CSS β€” from simple hover effects to complex multi-step keyframe animations and 3D transforms.

Background

CSS animations make interfaces feel alive and responsive. Done well, they guide user attention, provide feedback, and delight users. Done poorly, they cause motion sickness and slow pages. This lab teaches both the technique and the taste.

Time

30 minutes

Prerequisites

  • Lab 07: CSS Flexbox

  • Lab 08: CSS Grid

Tools

docker run --rm -it -v /tmp:/workspace zchencow/innozverse-htmlcss:latest bash

Lab Instructions

Step 1: CSS Transitions

Write this file:

πŸ’‘ transition animates CSS property changes. transition: all 0.3s ease catches everything but is inefficient β€” name specific properties. Only transform and opacity are GPU-accelerated and won't cause layout reflow. Prefer those for performance.

πŸ“Έ Verified Output:


Step 2: CSS Transforms

Write this file:

πŸ’‘ Transforms don't affect layout β€” they move/scale the painted element without pushing other elements around. This makes them perfect for animations. Multiple transforms combine left-to-right: transform: translateY(-5px) scale(1.1) translates first, then scales.

πŸ“Έ Verified Output:


Step 3: @keyframes Animations

Write this file:

πŸ’‘ @keyframes defines the animation sequence. Use from/to for simple start-end or 0%, 50%, 100% for multi-step. Staggered animation-delay creates a cascade effect. animation-fill-mode: forwards keeps the final state after the animation ends.

πŸ“Έ Verified Output:


Step 4: Animation Properties

Write this file:

πŸ’‘ Key animation properties: animation-iteration-count (infinite or number), animation-direction (normal/reverse/alternate), animation-fill-mode (forwards = stay at end), animation-play-state (running/paused β€” controllable with JavaScript).

πŸ“Έ Verified Output:


Step 5: Hover Effects & Interactive Animations

Write this file:

πŸ’‘ CSS pseudo-elements (::before, ::after) add decorative content without extra HTML. The ripple effect uses a pseudo-element that starts at 0 size and grows to cover the button on hover. overflow: hidden clips it to the button shape.

πŸ“Έ Verified Output:


Step 6: Loading Spinner Animation

Write this file:

πŸ’‘ Loading indicators reduce perceived wait time and prevent users from thinking something broke. The shimmer/skeleton loader is especially effective β€” it shows content shape before data loads, reducing layout shift when content appears (better CLS score).

πŸ“Έ Verified Output:


Step 7: Card Flip Animation (3D Transforms)

Write this file:

πŸ’‘ 3D transforms require three things: perspective on the parent (creates depth), transform-style: preserve-3d on the flip container, and backface-visibility: hidden on each face. perspective: 1000px means the vanishing point is 1000px away β€” smaller = more dramatic 3D effect.

πŸ“Έ Verified Output:


Step 8: Capstone β€” Animated Hero Section

Write this file:

πŸ’‘ Animation checklist: Use animation-fill-mode: both to apply the start state immediately. Stagger delays with multiples of 0.2s for elegant cascades. Always check prefers-reduced-motion in production for accessibility. Gradient animations use background-size: 400% to give the position something to move through.

πŸ“Έ Verified Output:


Verification

Summary

Concept
CSS
Best For

Transitions

transition: prop dur ease

Hover/focus state changes

Transforms

transform: translate/rotate/scale

Movement without layout reflow

Keyframes

@keyframes name { ... }

Complex multi-step animations

3D

perspective, preserve-3d

Flip cards, depth effects

Performance

transform + opacity only

GPU-accelerated, no reflow

Further Reading

Last updated