docs.rodeo

MDN Web Docs mirror

transition

{{CSSRef}} 

The transition CSS property is a shorthand property for {{ cssxref("transition-property") }} , {{ cssxref("transition-duration") }} , {{ cssxref("transition-timing-function") }} , {{ cssxref("transition-delay") }} , and {{ cssxref("transition-behavior") }} .

{{EmbedInteractiveExample("pages/css/transition.html")}} 

Transitions enable you to define the transition between two states of an element. Different states may be defined using pseudo-classes like {{cssxref(":hover")}}  or {{cssxref(":active")}}  or dynamically set using JavaScript.

Constituent properties

This property is a shorthand for the following CSS properties:

Syntax

/* Apply to 1 property */
/* property name | duration */
transition: margin-right 4s;

/* property name | duration | delay */
transition: margin-right 4s 1s;

/* property name | duration | easing function */
transition: margin-right 4s ease-in-out;

/* property name | duration | easing function | delay */
transition: margin-right 4s ease-in-out 1s;

/* property name | duration | behavior */
transition: display 4s allow-discrete;

/* Apply to 2 properties */
transition:
  margin-right 4s,
  color 1s;

/* Apply to all changed properties */
transition: all 0.5s ease-out allow-discrete;
transition: 200ms linear 50ms;

/* Global values */
transition: inherit;
transition: initial;
transition: revert;
transition: revert-layer;
transition: unset;

The transition property value is specified as one of the following:

Each single-property transition describes the transition that should be applied to a single property or all properties. It includes:

If you specify all as the transition property for one single-property transition, but then specify subsequent single-property transitions with {{cssxref("<custom-ident>")}}  values, those subsequent transitions will override the first one. For example:

transition:
  all 200ms,
  opacity 400ms;

In this case, all the properties that change as the element changes state will transition with a duration of 200ms except for {{cssxref("opacity")}} , which will take 400ms to transition.

See how things are handled when lists of property values aren’t the same length. In short, extra transition descriptions beyond the number of properties actually being animated are ignored.

Formal definition

{{CSSInfo}} 

Formal syntax

{{csssyntax}} 

Examples

Basic example

In this example, when the user hovers over the element, there is a half-second (500ms) delay before a two-second background-color transition occurs.

HTML

<a class="target">Hover over me</a>

CSS

We include two {{cssxref("time")}}  values. In the transition shorthand, the first <time> value is the transition-duration. The second time value is the transition-delay. Both default to 0s if omitted.

.target {
  font-size: 2rem;
  background-color: palegoldenrod;
  transition: background-color 2s 500ms;
}

.target:hover {
  background-color: darkorange;
}

{{EmbedLiveSample('Basic_example', 600, 100)}} 

Specifications

{{Specifications}} 

Browser compatibility

{{Compat}} 

See also

In this article

View on MDN