What Are CSS Animations?
CSS animations let you animate HTML elements without JavaScript. They use @keyframes rules to define animation states and the animation shorthand property to control timing, duration, and iteration. CSS animations are GPU-accelerated and perform well for transitions, hover effects, and loading indicators.
Animation Properties
- animation-name: References a
@keyframesrule. - animation-duration: How long one cycle takes (e.g., 1s, 500ms).
- animation-timing-function: Speed curve (ease, linear, ease-in-out, etc.).
- animation-iteration-count: Number of times the animation repeats (number or
infinite).
Frequently Asked Questions
Are CSS animations better than JavaScript animations?
For simple transitions and decorative effects, CSS animations are often more performant because they can be offloaded to the GPU. JavaScript animations offer more control for complex, interactive, or physics-based sequences.
Can I combine multiple animations on one element?
Yes. Separate multiple animation values with commas in the animation property. Each animation can have its own keyframes, duration, and timing function.