liveBook · Manning

Animation duration

As explained in Tiny CSS Projects

The CSS animation-duration property specifies the length of time an animation takes to complete one cycle.

A loading animation needs a pace. The CSS `animation-duration` property sets how long one run through its keyframes takes, from start to finish. Write the time in seconds (`s`) or milliseconds (`ms`). A longer duration makes the same animation complete more slowly. section 3.4.2

Imagine a loader made of rectangles that shrink halfway through an animation and return to full height at the end. Give the rectangles an `animation-name` that matches the keyframes, then set `animation-duration: 2.2s` to make each complete cycle take 2.2 seconds. section 3.4.1 section 3.4.2

Listing 3.8 Added animation duration
rect {
  animation-name: doScale;
  animation-duration: 2.2s;
}

The rectangle rule places `animation-duration` beside `animation-name`: the name selects the keyframes, and the duration sets the time for one run. section 3.4.2

Duration does not make the loader repeat. With only a name and duration set, the rectangles animate once and stop. Use `animation-iteration-count` to control repetition and `animation-delay` to stagger when individual rectangles start. Duration, name, and iteration count can also be written together in the `animation` shorthand. section 3.4.2 section 3.4 section 3.4.4

Choose the time by watching the result. A quick change of state might take around 250 milliseconds; a larger panel change might take around 500 milliseconds. A loader calls for trial and error because people may watch it longer. Avoid motion that feels imperceptibly fast or laggy, and consider people sensitive to motion. For flashing animations, keep the flash rate at no more than three times per second. section 3.4.2

How Tiny CSS Projects covers it

How deep it goes
Defines the property and its units, demonstrates a 2.2-second value, and discusses practical timing choices.
Examples
Uses shrinking SVG rectangles in a loader and contrasts short interface animations with a longer loader cycle.
What it assumes
Introduces CSS keyframes and animation-name before adding duration to animated rectangles.
What you can do after
Operate/configure it by setting and tuning the time for one cycle of a CSS loading animation.
How it connects
Connects animation duration to CSS keyframes, animation-name, animation-delay, animation-iteration-count, and animation shorthand.

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.