Keyframes and timing do the work
CSS animation splits into keyframes, which state what the element looks like at given moments, and animation properties, which set duration, easing, iteration and direction. Duration controls one cycle, easing sets speed change, infinite loop maps to iteration-count, and normal versus alternate maps to direction. Copy the generated code, load the example, or reset.
Steps
- Choose movement: translate, rotate, scale, opacity, in combination.
- Set duration — 0.2 to 0.4 seconds for micro-interaction, 0.6 to 1.2 for visible effects.
- Pick easing: ease-out for entrances, linear or ease-in-out for loops.
- Tick infinite for continuous motion and alternate for ping-pong.
- Generate, preview, copy, and paste into the stylesheet.
Percentages in keyframes
Percentages mark moments, zero the start and one hundred the end, with interpolation filling gaps. To alter pacing mid-way, add an intermediate frame, for example hitting the target at fifty and settling back. Interpolation stays continuous only when the same property appears across frames; different properties are declared separately. Multiple transform functions belong on one line in one frame — splitting them overrides rather than composes. And animating from display none requires switching to a rendered display first.
Alternate and loop combinations
Alternate with infinite produces a ping-pong breath, good for pulsing highlights. Infinite without alternate snaps back at the end, which jars unless first and last states match. Reverse handles exits as entrances played backwards. Odd iteration counts with alternate finish on the end state instead of the start — watch the resting frame. Fill mode forwards holds the final frame and prevents the jump.
Performance and accessibility
Animate transform and opacity, never width, top or margin, which trigger layout and stutter. will-change promotes layers early but costs memory if overused and should be removed afterwards. Long infinite animations drain mobile batteries and belong paused when the page is hidden. Reduced-motion media queries must collapse durations to nearly zero, since large translations nauseate vestibular-sensitive users. And animation must never block input — button feedback stays immediate.
Common problems:Mixing animation and transition double-fires. Durations past 1.5 seconds feel sluggish. Infinite loops over reading areas distract. Duplicate keyframe names silently override. Percentage translates break when the parent resizes; use fixed units or transforms. Missing initial states cause a first-frame jump. And animations that end mid-path leave elements stranded.