What is the difference between CSS transitions and CSS animations?
Answer
CSS transitions animate a property change from one state to another when a trigger occurs (usually a class change or :hover). They are defined by specifying which property to transition, the duration, and the easing: transition: background-color 0.3s ease;. They only have a start and end state. CSS animations use @keyframes to define multiple intermediate states and run automatically without a trigger. They support looping (animation-iteration-count: infinite), direction (alternate), delay, and fill modes. Use transitions for simple hover effects and UI feedback. Use animations for complex, multi-step, or continuously looping effects like spinners, pulses, and entrance animations.
Previous
How does Flexbox differ from CSS Grid? When would you use each?
Next
What are HTML data attributes (data-*)?
More HTML / CSS Questions
View all →- Intermediate How does the CSS cascade work?
- Intermediate What is BEM (Block Element Modifier) methodology in CSS?
- Intermediate What are CSS custom properties (CSS variables)?
- Intermediate What is the difference between em, rem, px, vh, and vw units in CSS?
- Intermediate How does Flexbox differ from CSS Grid? When would you use each?