CSS propertyTransitions
transition-duration
Sets how long a transition lasts.
- Initial value
0s- Inherited
- No
- Animatable
- no
- Applies to
- all elements and the ::before and ::after pseudo-elements
- JavaScript
element.style.transitionDuration = "300ms"
Example
#CSS
.menu {
transition-property: opacity, transform;
transition-duration: 150ms, 300ms;
}Example HTML
<p style="margin: 0; color: #a3a3a3;">Opacity changes in 150 ms and movement in 300 ms.</p>Preview
Definition and usage
#The transition-duration property sets the transition time in seconds (s) or milliseconds (ms). The default 0s means no animation, so without this value the transition does not work at all.
You can provide a comma-separated list of durations, assigned in order to the properties from transition-property.
Match the duration to the distance and weight of the change: small colour changes need about 150 ms, movements of larger panels 250-400 ms.
Syntax
#Syntax
transition-duration: <time> [, <time>]*;Values
#Values in practice
#0s
An immediate change.
.demo { transition-duration: 0s; }150ms
A very fast transition.
.demo { transition-duration: 150ms; }0.6s
A clearly visible but snappy transition.
.demo { transition-duration: 0.6s; }1.4s
A slow transition, the whole movement is easy to see.
.demo { transition-duration: 1.4s; }Browser support
#Widely available
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#- An element’s entrance can take slightly longer than its exit. Hiding quickly makes the interface feel responsive.
- Respect
prefers-reduced-motion: with this preference, shorten or disable motion transitions.
Related entries
#Practise it in lessons
#Spotted a mistake or missing an example? Write to us.