CSS3 transition-duration Property
Example
The transition appears over the last 5 seconds:
transition-duration: 5s;
-webkit-transition-duration: 5s; /* Safari */
Try it »
Browser support
The numbers in the table indicate the first browser version that supports this property.
A number immediately before -webkit-, -ms-, or -moz- indicates the first browser version that supports that prefixed property.
| property | |||||
|---|---|---|---|---|---|
| transition-duration | 26.0 | ||||
| 4.0 -webkit- | 10.0 | 16.0 | |||
| 4.0 -moz- | 6.1 | ||||
| 3.1 -webkit- | 12.1 | ||||
| 10.5 -o- |
Property definition and usage
transition-duration is a CSS3 property used to specify the duration of a transition effect. It defines the length of time a transition takes from start to finish, making transitions smoother and more natural.
The value can be in seconds (s) or milliseconds (ms), representing the duration of the transition. Decimal values can be used for a more precise duration.
For example, if you want the transition to last 1 second, you can write:
.element {
transition-duration: 1s;
}
If you want the transition to last 500 milliseconds, you can write:
.element {
transition-duration: 500ms;
}
You can also apply multiple transitions to an element at once and specify a different duration for each. This can be done with comma-separated values:
.element {
transition-property: width, height, opacity;
transition-duration: 0.5s, 1s, 0.3s;
}
In this way, the width transition lasts 0.5 seconds, the height transition lasts 1 second, and the opacity transition lasts 0.3 seconds.
By adjusting the transition-duration property, you can control the speed and smoothness of transitions, creating more appealing user interface interactions.
| Default value: | 0 |
|---|---|
| Inherited: | no |
| Version: | CSS3 |
| JavaScript syntax: | object.style.transitionDuration="5s" |
Syntax
transition-duration:
time
;
| Value | Description |
|---|---|
| time | Specifies how long the transition takes to complete (in seconds or milliseconds). The default is 0, meaning no effect. |