CSS transition Property Explained

What the CSS transition property does, with an example.

Published November 5, 2026

transition animates changes of CSS properties smoothly over a duration instead of switching instantly: transition: <property> <duration> <timing> <delay>.

How it works

The transition is defined on the element's base state and runs when the property changes (hover, class toggle, media query).

Animate cheap properties (transform, opacity) for smoothness.

Values and effects

transition: all .3s ease; → everything over 0.3s
transition: opacity .2s; → fade
transition: transform .3s cubic-bezier(.2,.8,.2,1); → custom easing
transition: background .2s ease-in-out .1s; → with delay

Practical examples

Hover button

.btn { background: #2f81f7; transition: background .2s, transform .2s; }
.btn:hover { background: #1f6feb; transform: translateY(-1px); }

Respect reduced motion

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

Height auto trick

.panel { display: grid; grid-template-rows: 0fr; transition: grid-template-rows .3s; }
.panel.open { grid-template-rows: 1fr; }

Common mistakes

  • Using transition: all everywhere.
  • Trying to transition to display:none or height:auto.
  • Ignoring prefers-reduced-motion.

Key takeaways

  • transition in one line: transition animates changes of CSS properties smoothly over a duration instead of switching instantly: transition: <property> <duration> <timing> <delay>.
  • Inspect it live in DevTools → Styles.
  • Test across browsers and screen sizes.

FAQ

Why won't it animate?

The property isn't animatable, or the transition is only declared on the end state.

Is transition supported in all browsers?

Yes in all modern browsers; check caniuse.com for edge cases.

More CSS articles