CSS Reference ยท Transforms, Transitions and Animations
The transition-duration property
Reference for the CSS transition-duration property: set how long a transition lasts in seconds or milliseconds, with syntax, examples and browser support.
The transition-duration property sets how long a transition takes to go from the old value to the new one. The default is 0s, which means changes are instant, so a transition never appears until you set a duration.
You can give one time for all properties, or a comma-separated list with one time per property listed in transition-property.
.panel { transition-property: opacity, transform; transition-duration: 200ms, 400ms; }
Try it
Syntax
transition-duration: <time># /* examples */ transition-duration: 0.3s; transition-duration: 300ms; transition-duration: 200ms, 1s;
- Initial value:
0s - Applies to: all elements, and the
::beforeand::afterpseudo-elements - Inherited: no
- Animatable: no
- Computed value: as specified
Values
| Value | Description |
|---|---|
<time> |
A non-negative number with a unit: s (seconds) or ms (milliseconds). The unit is required, even for zero. |
| Comma-separated list | One duration per property in transition-property. A shorter list repeats; extra values are ignored. |
A negative value makes the declaration invalid. 0s means no visible transition, although the transition events may still fire.
Usage notes
- Always include a unit.
transition-duration: 0is invalid; write0s. - Typical ranges. Small state changes (hover colors, toggles) feel good at 100 to 250 ms. Larger moves such as panels sliding in usually need 250 to 500 ms. Past about a second, interfaces start to feel slow.
- Leaving can be faster than entering. Put a longer duration on the active state and a shorter one on the base rule to make hiding quicker than showing.
- Longhand order. In the shorthand, the first time is the duration and the second is the delay. With the longhands there is no confusion.
- Reduced motion. Under
prefers-reduced-motion: reduce, set a very short duration (such as1ms) rather than removing it, sotransitionendhandlers still run. - Test on slow devices. A transition that is smooth on a laptop can stutter on a phone when it animates layout properties.
Browser support
Supported in every browser.
Related
transitionโ the shorthandtransition-delayโ waits before startingtransition-timing-functionโ the speed curveanimation-durationโ the same idea for keyframe animations- Lesson: Transitions