The Idea
Normally a style change happens instantly. A transition makes it happen gradually over time.
transition-duration on the button: 0.3s, 0.2s
Put the transition on the normal state so it works both going in and going back.
The Four Parts
| Property | Meaning | Example |
|---|---|---|
transition-property | Which property animates | background-color, all |
transition-duration | How long | .3s, 300ms |
transition-timing-function | Speed curve | ease, linear, ease-in-out |
transition-delay | Wait before starting | .1s |
Shorthand order: property duration timing-function delay.
Timing Functions
| Value | Feel |
|---|---|
linear | Constant speed |
ease | Starts fast, ends slow (default) |
ease-in | Starts slow |
ease-out | Ends slow, feels natural for things entering |
cubic-bezier(.2,.8,.2,1) | Your own curve |
steps(4) | Jumps in steps |
What Can Be Transitioned?
Properties with number-like values: color, background-color, opacity, transform, width, margin, box-shadow. But display cannot animate between none and block.
transform and opacity. They run smoothly. Animating width, height, top or left forces the browser to re-lay out the page and can look choppy.
Fade a Menu In
Using visibility along with opacity keeps hidden links out of the tab order and away from screen readers until shown.
Underline That Grows
Practice
- Add a smooth hover and focus effect to a button
- Fade a card's shadow in on hover
- Make a dropdown menu fade and slide in
Conclusion
Transitions smooth the change between two states. Set property, duration and easing on the normal state and prefer transform and opacity.

