The transition
CSS property is a shorthand property for transition-property
, transition-duration
, transition-timing-function
, and transition-delay
.
/* Apply to 1 property */ /* property name | duration */ transition: margin-left 4s; /* property name | duration | delay */ transition: margin-left 4s 1s; /* property name | duration | timing function | delay */ transition: margin-left 4s ease-in-out 1s; /* Apply to 2 properties */ transition: margin-left 4s, color 1s; /* Apply to all changed properties */ transition: all 0.5s ease-out; /* Global values */ transition: inherit; transition: initial; transition: unset;
Transitions enable you to define the transition between two states of an element. Different states may be defined using pseudo-classes like :hover
or :active
or dynamically set using JavaScript.
Initial value | as each of the properties of the shorthand: |
---|---|
Applies to | all elements, ::before and ::after pseudo-elements |
Inherited | no |
Media | interactive |
Computed value | as each of the properties of the shorthand:
|
Animation type | discrete |
Canonical order | order of appearance in the formal grammar of the values |
Syntax
The transition
property is specified as one or more single-property transitions, separated by commas.
Each single-property transition describes the transition that should be applied to a single property (or the special values all
and none
). It includes:
- zero or one value representing the property to which the transition should apply. This may be any one of:
- the keyword
none
- the keyword
all
- a
<custom-ident>
naming a CSS property.
- the keyword
- zero or one
<single-transition-timing-function>
value representing the timing function to use - zero, one, or two
<time>
values. The first value that can be parsed as a time is assigned to thetransition-duration
, and the second value that can be parsed as a time is assigned totransition-delay
.
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 syntax
<single-transition>#where
<single-transition> = [ none | <single-transition-property> ] || <time> || <single-transition-timing-function> || <time>
where
<single-transition-property> = all | <custom-ident>
<single-transition-timing-function> = <single-timing-function>where
<single-timing-function> = linear | <cubic-bezier-timing-function> | <step-timing-function> | <frames-timing-function>
where
<cubic-bezier-timing-function> = ease | ease-in | ease-out | ease-in-out | cubic-bezier(<number>, <number>, <number>, <number>)
<step-timing-function> = step-start | step-end | steps(<integer>[, [ start | end ] ]?)
<frames-timing-function> = frames(<integer>)
Examples
There are several more examples of CSS transitions included in the main CSS transitions article.
Specifications
Specification | Status | Comment |
---|---|---|
CSS Transitions The definition of 'transition' in that specification. |
Working Draft | Initial definition |
Browser compatibility
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | 1.0 -webkit 26.0 # |
(Yes)-webkit (Yes) |
4.0 (2.0) -moz 16.0 (16.0)[1] |
10.0 | 10.1 -o 12.10 # |
3.0 -webkit 6.1 |
Gradients[2] | No support | (Yes) | No support | 10.0 | No support | No support |
frames() timing function |
No support[3] | ? | No support[3] | No support | No support[3] | ? |
Feature | Android | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | 2.1 -webkit | (Yes)-webkit (Yes) |
4.0 (2.0) -moz 16.0 (16.0)[1] |
10.0 | 10.0 -o 12.10 # |
3.2 -webkit |
Gradients[1] | No support | (Yes) | No support | 10.0 | No support | No support |
frames() timing function |
? | ? | No support[3] | No support | (Yes) | ? |
[1] In addition to the unprefixed support, Gecko 44.0 (Firefox 44.0 / Thunderbird 44.0 / SeaMonkey 2.41) added support for a -webkit
prefixed version of the property for web compatibility reasons behind the preference layout.css.prefixes.webkit
, defaulting to false
. Since Gecko 49.0 (Firefox 49.0 / Thunderbird 49.0 / SeaMonkey 2.46) the preference defaults to true
.
[2] PPK test
[3] The name of the frames()
timing function is currently under discussion, so it is currently disabled in browser release versions until a final decision is reached. It is currently turned on in Nightly/Canary only.