Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Transforms, Transitions and Animations

The transition property

Reference for the CSS transition shorthand: property, duration, easing, delay and behavior in one declaration, with syntax, examples and browser support.

The transition property makes a change in a CSS value happen gradually instead of instantly. When a property that has a transition changes (for example on :hover, when a class is added, or when a media query starts to match), the browser computes the in-between values over the given time.

It is a shorthand for transition-property, transition-duration, transition-timing-function, transition-delay and transition-behavior. Put it on the element's normal rule, not only on the state that triggers the change, so it works in both directions.

CSS
.button {
  transition: background-color 200ms ease-out;
}

.button:hover {
  background-color: #1e40af;
}

Try it

Click to move the dots

Each dot gets the same class change (.go on the page), but a different transition value, so each one moves in its own way. Press the button again to see the transitions run backward.

Several properties at once

Syntax

CSS
transition: <single-transition>#

<single-transition> =
  [ none | <property-name> ] || <duration> || <easing-function> || <delay> || <transition-behavior>
  • Initial value: all 0s ease 0s normal (so by default nothing animates, because the duration is zero)
  • Applies to: all elements, and the ::before and ::after pseudo-elements
  • Inherited: no
  • Animatable: no
  • Computed value: as specified, for each of the longhand properties

Values

Value Description
<property-name> A property to animate, such as opacity, or the keyword all. See transition-property.
none No transition. Must be the only item in the list.
First <time> The duration: 300ms or 0.3s.
Second <time> The delay before the transition starts.
<easing-function> The speed curve: ease, linear, cubic-bezier(), steps(), linear().
normal / allow-discrete Whether non-animatable (discrete) properties flip partway. See transition-behavior.
Comma-separated list Several transitions on one element, each with its own settings.

Usage notes

  • Two times, two meanings. The first time value is always the duration, the second is the delay. transition: opacity 1s 2s waits two seconds, then fades for one.
  • A duration is required. With the default duration of 0s, transition: opacity does nothing visible.
  • Declare it on the base rule. If it only appears on :hover, the change in is smooth and the change back snaps, because the transition belongs to the state the element is entering.
  • Prefer listing properties. transition: all is convenient but animates every change, including ones you did not intend (such as layout properties), and can cause jank. Name opacity, transform or background-color explicitly.
  • Cheap properties. transform and opacity usually animate smoothly; animating width, height or top forces layout work on every frame.
  • No transition on first render. An element that is just inserted has no earlier value to change from. Use @starting-style for entry animations.
  • Interrupting. If the value changes again mid-transition, the browser starts a new transition from the current value toward the new target.
  • Events. transitionrun, transitionstart, transitionend and transitioncancel fire on the element, once per property.
  • Reduced motion. Shorten or remove transitions inside @media (prefers-reduced-motion: reduce) when they involve large movement.

Browser support

The transition shorthand is supported in every browser. The transition-behavior part is newer; check a compatibility table before depending on it.