CSS Transition
In one line
A CSS transition smoothly interpolates a property from one value to another over a specified duration.
In simple words
CSS transitions let you smoothly animate changes to CSS properties. When a property changes value (e.g., on hover), the browser interpolates between the old and new values over a duration you specify, creating a smooth animation.
The transition shorthand takes: property, duration, timing function, and delay. For example, transition: background 0.3s ease animates the background color over 0.3 seconds with an ease curve. You can transition multiple properties with commas.
Transitions are triggered by property changes — usually from pseudo-classes like :hover, :focus, or class changes via JavaScript. Not all properties are transitionable (display cannot transition), but most visual properties (color, opacity, transform, width, height) can be. Transitions are simpler than @keyframes animations and are ideal for simple state changes.
Example
.btn {
background: blue;
transition: background 0.3s ease, transform 0.2s;
}
.btn:hover {
background: darkblue;
transform: scale(1.05);
}A button that smoothly changes background color and scales up on hover, over 0.3s and 0.2s respectively.
Related terms
Related Resources
Related Lessons
- CSS Animations
Transitions and animations.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.