liveBook · Manning

Animation property

As explained in Tiny CSS Projects

The CSS animation property is a shorthand property for configuring an element's animation name, timing, duration, iteration, and related behavior.

A loading indicator reassures people that a task is still running. The CSS `animation` property lets an element use named keyframes and sets behavior such as duration, repetition, and delay. Keep explanatory text alongside a loader so its purpose is available to screen-reader users. section 3.0 section 3.4

Start with SVG rectangles that grow and shrink toward their centers. Define that movement with keyframes, then apply the same animation to each rectangle. Give the rectangles different start delays so they reach different heights at the same time, creating a ripple effect. section 3.4

Combine three animation settings

Instead of separate `animation-name`, `animation-duration`, and `animation-iteration-count` declarations, write `rect { animation: doScale 2.2s infinite; }`. This applies the named keyframes, makes each run last 2.2 seconds, and repeats it indefinitely. Settings omitted from the shorthand or separate declarations use their defaults. section 3.4.4

The shorthand is a convenience, not a requirement: separate declarations are equally valid. To stagger this loader, set a different `animation-delay` on individual rectangles after applying their shared animation. section 3.4.4 section 3.4

Listing 3.13 Disabling the animation for users who prefer reduced motion
@media (prefers-reduced-motion: reduce) {     #1
  rect { animation: none; }                   #2
}

Motion can make some users ill. This listing shows how `@media (prefers-reduced-motion: reduce)` can set `animation: none` on the rectangles when a user requests reduced motion. section 3.5

How Tiny CSS Projects covers it

How deep it goes
Works through named keyframes, duration, repetition, shorthand defaults, and staggered delays; does not detail every animation setting.
Examples
Uses shrinking SVG rectangles, the `animation: doScale 2.2s infinite` declaration, and a reduced-motion override.
What it assumes
Introduces animation controls before combining them; begins with elements to animate rather than assuming knowledge of the shorthand.
What you can do after
Build it from scratch: apply a repeating keyframe animation to a loader, stagger its elements, and disable motion conditionally.
How it connects
Connects CSS keyframes and animation-delay to SVG styling and the prefers-reduced-motion media query.

Also explained in

Compare how 2 books explain animation property →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Tiny CSS Projects. The section links point to the parts of the book it draws on.