Each feature in detail MDN The transition CSS shorthand property for transition-property , transition-duration , transition-timing-function , transition-delay , and transition-behavior .
Live preview Example from MDN
transition: margin-right 2s; transition: margin-right 2s 0.5s; transition: margin-right 2s ease-in-out; transition: margin-right 2s ease-in-out 0.5s; transition:
margin-right 2s,
color 1s; transition: all 1s ease-out;
#example-element {
background-color : #e4f0f5 ;
color : black ;
padding : 1 rem ;
border-radius : 0.5 rem ;
font : 1 em monospace ;
width : 100 % ;
transition : margin-right 2 s ;
}
#default-example:hover > #example-element {
background-color : #990099 ;
color : white ;
margin-right : 40 % ;
} < section id = "default-example" >
< div id = "example-element" >Hover to see< br />the transition.</ div >
</ section > Syntax <single-transition># Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.
Browser support First browser version supporting transition Chrome 26 Edge 12 Firefox 16 Safari 9 Chrome Android 26 Safari iOS 9
First version with support, from MDN browser-compat-data.
Specification ↗ MDN reference ↗
MDN The transition-behavior CSS property specifies whether transitions will be started for properties whose animation behavior is discrete .
Live preview Example from MDN
html {
font-family : "Helvetica" , "Arial" , sans-serif ;
}
[ popover ] {
font-size : 1.2 rem ;
padding : 10 px ;
}
[ popover ]: popover-open {
opacity : 1 ;
transform : scaleX ( 1 );
}
[ popover ] {
/* Final state of the exit animation */
opacity : 0 ;
transform : scaleX ( 0 );
transition-property : opacity, transform, overlay , display;
transition-duration : 0.7 s ;
transition-behavior : allow-discrete;
/* Using the shorthand transition property, we could write:
transition:
opacity 0.7s,
transform 0.7s,
overlay 0.7s allow-discrete,
display 0.7s allow-discrete;
or even:
transition: all 0.7s allow-discrete;
*/
}
/* Needs to be included after the previous [popover]:popover-open
rule to take effect, as the specificity is the same */
@starting-style {
[ popover ]: popover-open {
opacity : 0 ;
transform : scaleX ( 0 );
}
} < button popovertarget = "mypopover" >Show the popover</ button >
< div popover = "auto" id = "mypopover" >I'm a Popover! I should animate.</ div > Syntax <transition-behavior-value># Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.
Definition Initial normal Applies to All elements Inherited no Percentages N/A Computed value as specified Canonical order per grammar Animation type not animatable Browser support First browser version supporting transition-behavior Chrome 117 Edge 117 Firefox 129 Safari 17.4 Chrome Android 117 Safari iOS 17.4
First version with support, from MDN browser-compat-data.
Specification ↗ MDN reference ↗
MDN The transition-delay CSS property specifies the duration to wait before starting a property's transition effect when its value changes.
Live preview Example from MDN
transition-delay: 250ms;
transition-property: margin-right; transition-delay: 1s;
transition-property: background-color; transition-delay: 1s;
transition-property: margin-right, color; transition-delay: 1s, 250ms;
transition-property: margin-right, color;
#example-element {
background-color : #e4f0f5 ;
color : black ;
padding : 1 rem ;
border-radius : 0.5 rem ;
font : 1 em monospace ;
width : 100 % ;
transition : margin-right 2 s ;
}
#default-example:hover > #example-element {
background-color : #990099 ;
color : white ;
margin-right : 40 % ;
} < section id = "default-example" >
< div id = "example-element" >Hover to see< br />the transition.</ div >
</ section > Syntax <time># Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.
Definition Initial 0s Applies to all elements Inherited no Percentages N/A Computed value list, each item a duration Canonical order per grammar Animation type not animatable Browser support First browser version supporting transition-delay Chrome 26 Edge 12 Firefox 16 Safari 9 Chrome Android 26 Safari iOS 9
First version with support, from MDN browser-compat-data.
Specification ↗ MDN reference ↗
MDN The transition-duration CSS property sets the length of time a transition animation should take to complete. By default, the value is 0s, meaning that no animation will occur.
Live preview Example from MDN
transition-duration: 500ms;
transition-property: margin-right; transition-duration: 2s;
transition-property: background-color; transition-duration: 2s;
transition-property: margin-right, color; transition-duration: 3s, 1s;
transition-property: margin-right, color;
#example-element {
background-color : #e4f0f5 ;
color : black ;
padding : 1 rem ;
border-radius : 0.5 rem ;
font : 1 em monospace ;
width : 100 % ;
transition : margin-right 2 s ;
}
#default-example:hover > #example-element {
background-color : #990099 ;
color : white ;
margin-right : 40 % ;
} < section id = "default-example" >
< div id = "example-element" >Hover to see< br />the transition.</ div >
</ section > Syntax <time [0s,∞]># Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.
Definition Initial 0s Applies to all elements Inherited no Percentages N/A Computed value list, each item a duration Canonical order per grammar Animation type not animatable Browser support First browser version supporting transition-duration Chrome 26 Edge 12 Firefox 16 Safari 9 Chrome Android 26 Safari iOS 9
First version with support, from MDN browser-compat-data.
Specification ↗ MDN reference ↗
MDN The transition-property CSS property sets the CSS properties to which a transition effect should be applied.
Live preview Example from MDN
transition-property: margin-right; transition-property: margin-right, color; transition-property: all; transition-property: none;
#example-element {
background-color : #e4f0f5 ;
color : black ;
padding : 1 rem ;
border-radius : 0.5 rem ;
font : 1 em monospace ;
width : 100 % ;
transition : margin-right 2 s ;
}
#default-example:hover > #example-element {
background-color : #990099 ;
color : white ;
margin-right : 40 % ;
} < section id = "default-example" >
< div id = "example-element" >Hover to see< br />the transition.</ div >
</ section > Syntax none | <single-transition-property># Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.
Definition Initial all Applies to all elements Inherited no Percentages N/A Computed value the keyword none else a list of identifiers Canonical order per grammar Animation type not animatable Browser support First browser version supporting transition-property Chrome 26 Edge 12 Firefox 16 Safari 9 Chrome Android 26 Safari iOS 9
First version with support, from MDN browser-compat-data.
Specification ↗ MDN reference ↗
MDN The transition-timing-function CSS property sets how intermediate values are calculated for CSS properties being affected by a transition effect .
Live preview Example from MDN
transition-timing-function: linear; transition-timing-function: ease-in; transition-timing-function: steps(6, end); transition-timing-function: cubic-bezier(0.29, 1.01, 1, -0.68);
#example-element {
background-color : #e4f0f5 ;
color : black ;
padding : 1 rem ;
border-radius : 0.5 rem ;
font : 1 em monospace ;
width : 100 % ;
transition : margin-right 2 s ;
}
#default-example:hover > #example-element {
background-color : #990099 ;
color : white ;
margin-right : 40 % ;
} < section id = "default-example" >
< div id = "example-element" >Hover to see< br />the transition.</ div >
</ section > Syntax <easing-function># Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.
Definition Initial ease Applies to all elements Inherited no Percentages N/A Computed value as specified Canonical order per grammar Animation type not animatable Browser support First browser version supporting transition-timing-function Chrome 26 Edge 12 Firefox 16 Safari 9 Chrome Android 26 Safari iOS 9
First version with support, from MDN browser-compat-data.
Specification ↗ MDN reference ↗
Spec The @starting-style rule is a grouping rule. The style rules inside it are used to establish styles to transition from, if the previous style change event did not establish a before-change style for the element whose styles are being computed.
MDN The @starting-style CSS at-rule is used to define starting values for properties set on an element that you want to transition from when the element receives its first style update, i.e., when an element is first displayed on a previously loaded page.
Live preview Example from MDN
CSS HTML JS
Edit Reset Copy
div {
width : 200 px ;
height : 100 px ;
border : 1 px solid black ;
margin-top : 10 px ;
}
div ::after {
content : "class: " attr ( class );
position : relative ;
top : 3 px ;
left : 3 px ;
}
div {
background-color : yellow ;
transition : background-color 3 s ;
}
div .showing {
background-color : skyblue ;
}
@starting-style {
div .showing {
background-color : red ;
}
} < button >Display < code > < div > </ code ></ button > const btn = document. querySelector ( "button" );
btn. addEventListener ( "click" , () => {
btn.disabled = true ;
const divElem = document. createElement ( "div" );
divElem.classList. add ( "showing" );
document.body. append (divElem);
setTimeout (() => {
divElem.classList. remove ( "showing" );
setTimeout (() => {
divElem. remove ();
btn.disabled = false ;
}, 3000 );
}, 3000 );
}); Browser support First browser version supporting @starting-style Chrome 117 Edge 117 Firefox 129 Safari 17.5 Chrome Android 117 Safari iOS 17.5
First version with support, from MDN browser-compat-data.
Specification ↗ MDN reference ↗