Animation and transition precedence
Definition and purpose
Animations and transitions participate in the cascade through generated values. A running animation can override normal author declarations, while important declarations override animations. An active CSS transition can temporarily override even important declarations.
Animation over normal
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } @keyframes fade { from { opacity: 0; } to { opacity: 1; } } #a { opacity: 1; animation: fade 10s linear -5s paused; } </style> </head> <body> <div id="a">Sample</div> <div id="b">Other</div> </body></html>The paused animation contributes the midpoint.
Syntax and mental model
A paused animation with a negative delay provides a deterministic sample of its timeline. For transitions, compare before-change and after-change styles and sample while the transition is active. When it ends the target cascaded style remains. Merely declaring transition does not give the property transition precedence without an active transition.
Important over animation
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } @keyframes fade { from { opacity: 0; } to { opacity: 1; } } #a { opacity: 0.8 !important; animation: fade 10s linear -5s paused; } </style> </head> <body> <div id="a">Sample</div> <div id="b">Other</div> </body></html>The important declaration wins.
Common mistakes
An animation does not always win against inline CSS: important inline style wins over animation. Avoid using !important inside keyframes; such declarations are ignored.
Practice and next steps
After trying the examples, complete the linked coding exercise and review questions. Predict the result before running your code. Prerequisite: Value resolution stages. Next lesson: Formal value definition syntax.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Animation and transition precedence — knowledge check
Five questions on animation and transition precedence.
What beats normal author declarations during animation?
What beats the animation value?
What can beat important styles temporarily?
What does negative animation delay allow here?
After a transition ends, what remains?