Keyframe definitions
Keyframes define the states of your animation at specific points in time. Here are real examples from the Animation Playground:Animation properties
Duration
Controls how long one animation cycle takes to complete:Timing function
Controls the acceleration curve of the animation:Iteration count
Defines how many times the animation repeats:Direction
Controls whether the animation plays forward, backward, or alternates:Complete examples
Here’s how to combine all properties together:Animation control
You can pause and resume animations with JavaScript:Best practices
- Use
transformandopacityfor the best performance - Avoid animating
width,height, ormarginas they trigger layout recalculation - Keep animations under 300ms for UI feedback
- Use
will-changesparingly to hint at upcoming animations - Test on lower-end devices to ensure smooth playback
When to use CSS animations
CSS animations are ideal for:- Simple looping animations
- Hover and focus states
- Loading spinners and indicators
- Entrance and exit animations
- Animations that don’t require dynamic values