Transitions and timing
Definition and purpose
A transition interpolates between old and new values of a property when the computed style changes. It needs a trigger such as hover or focus, a transitionable property and a nonzero duration. CSS alone does not require a script for simple state changes.
A property-specific transition
<!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; } #a { opacity: 1; transition: opacity 200ms linear; } #a:hover { opacity: 0.7; } </style> </head> <body> <button id="a" type="button">Action</button> </body></html>Hover changes opacity over 200ms; the test checks configuration, not elapsed time.
Syntax and mental model
transition-property selects what changes smoothly; duration is travel time, delay postpones the start (negative delay starts partway through), and timing function maps elapsed progress to interpolation progress. linear gives a constant progress rate, ease changes rate, and steps jumps between levels. Discrete transitions need special handling; do not assume every property interpolates.
Delay and easing
<!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; } #a { transition: transform 300ms ease-in 100ms; } #a:focus-visible { transform: translateY(-2px); outline: 3px solid navy; } </style> </head> <body> <button id="a" type="button">Action</button> </body></html>Keyboard focus triggers a short movement after the delay while outline appears immediately.
Common mistakes
Avoid transition: all in complex components because unrelated style changes may animate. Keep a focus indication independent of the animation.
Practice and next steps
After trying the examples, complete the linked coding exercise and review questions. Predict the result before running your code. Prerequisite: 3D transforms and perspective. Next lesson: Keyframes and animation controls.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Transitions and timing — knowledge check
Five questions on transitions and timing.
What starts a normal CSS transition?
What does duration control?
What does a negative delay do?
Which easing has constant progress rate?
Why select a specific property instead of all?