Skip to content
BENIBIX Learn

CSS Transition

Design🎞️ Motion & VideoAnimation

Also known as CSS Transitions, transition Property

A CSS rule that makes a style change smooth. It runs between two states, like on hover.

Think of it like

It is like a dimmer switch. The light fades to the new level instead of snapping.

Example

Noah moves the mouse over his button. It fades from blue to navy in a fifth of a second.

Why it matters

It is the simplest way to add motion to a web page. It needs no script and very little code.

Definition

A CSS transition makes a style change happen smoothly instead of all at once. You say which property to animate, how long it takes and which easing to use. When the value changes, like on hover, the browser fills in the steps. It only runs from one state to another, so it cannot loop. For more than two states, use a CSS animation.

Example code

css
.button {
  background: blue;
  transition: background 200ms ease-out;
}
.button:hover {
  background: navy;
}
On hover, the button fades from blue to navy in 200 ms.
A transition's easing sets how its steps are spaced over time.

Common mistake

Moving width or top. Move transform and opacity instead, so it stays smooth on slow phones.

Key takeaways

  1. 1
    Two states. From one value to another.
  2. 2
    Property, time, easing. Three things to set.
  3. 3
    Animate cheap properties. Transform and opacity.

Compare