Transition-duration - Property CSS

transition-duration

Summary of characteristics of the transition-duration property

Quick description
Defines the duration of a transition, i.e. the time it takes to complete its transition.
Status
Standard
Applies to
All elements.
Usable for
HTML
Percentages
Not applicable.
Initial value
0s
Inherited by default
No.
Not animable: the transition-duration property cannot be animated.
Per grammar: serialization in the order of syntax.
W3C Module
CSS Transitions
 🡇  
 🡅  
Document status: WD (Working Draft)

Document status: WD (Working Draft)

Syntax diagram of transition-duration.

transition-duration - Syntax DiagramSyntax diagram of the transition-duration CSS property. duration duration , ,transition-duration:;transition-duration:;
Syntax diagram of the transition-duration property.
The links in the diagram provide more details about the values.

In the diagram, the bold terms are the predefined words of CSS, the other terms are described below:

  • duration is a duration: a numeric value followed by one of the CSS units of duration.
  • The syntax can be repeated as many times as there are transitions, separated by commas.

Description of the transition-duration property.

transition-duration defines the duration of the transition. This value must be set to a value greater than 0 seconds for the transition effect to be visible.

Let us recall that the transition effect consists of gradually changing the value of a property, and not abruptly. Once the transition is defined, each change in the property value will occur over the time defined by transition-duration. For more information on transitions in general, refer to shorthand property transition.

Values for transition-duration.

  • transition-duration: 5s;

    The transition will take place over a total duration of the indicated value. It is a positive number followed by one of CSS units of duration. The default value is 0, which cancels the effect of the transition.

  • transition-duration: 5s, 3s;

    Several values can be stated, separated by commas. This syntax can be used when multiple transitions are defined: see the page multiple transitions.

  • transition-duration: initial; (0s) transition-duration: inherit; transition-duration: revert; transition-duration: revertLayer; transition-duration: unset;

    See the following pages for more details: initial, inherit, revert, revert-layer, unset.

Animation of the transition-duration property.

The animation of transition-duration is not possible. Moreover, it would not make sense since this property is one of the parameters of the animation (or the transition).

Manipulating the transition-duration property programmatically.

With Javascript, change the value of transition-duration.

Examples of Javascript code to modify the value of transition-duration. The first syntax, in kebab-case is classic in CSS, while the second syntax is more common in Javascript.

Javascript
let el = document.getElementById('id'); el.style['transition-duration'] = '750ms'; // or let el = document.getElementById('id'); el.style.transitionDuration = '750ms';

With Javascript, read the value of transition-duration.

Two syntaxes equally for reading the value of transition-duration. The property must have been assigned directly to the element itself and not through a CSS selector. The duration is returned exactly as it was set, in the same unit.

Javascript
let el = document.getElementById('id'); let value = el.style['transition-duration']; // or let el = document.getElementById('id'); let value = el.style.transitionDuration;

With Javascript, read the computed value of transition-duration.

Below is how to read the computed value of transition-duration in Javascript. The duration is always returned in seconds, even if it was set in milliseconds.

Javascript
let el = document.getElementById('id'); let value = window.getComputedStyle(el).getPropertyValue('transition-duration');

With JQuery, change the value of transition-duration.

JQuery also allows the modification and reading of the value of the property transition-duration, with shorter syntaxes than those of Javascript.

JQuery

$('#id').css('transition-duration', '750ms');
// or
$('#id').css('transitionDuration', '750ms');

With JQuery, read the computed value of transition-duration.

JQuery
let value = $('#id').css('transition-duration');

Other code examples.

Other examples of Javascript and JQuery code are given on the page Javascript and CSS.

Test yourself.

The buttons below apply the entered value to the transition-duration property and then display either the value as it was applied, or the computed value. This second option allows you to see how the value of transition-duration is serialized. In particular, it is noted that the unit is always the second, even if the value was defined in milliseconds.

Simulator.

A transition has been set on the margin-left property of the blue element below. Enter a value for transition-duration, in seconds (2s) or in milliseconds (200ms), and then click the "Start" button. This will change the left margin of the element.

transition-duration :

Browsers compatibility with transition-duration.

Transition effects, and the property transition-duration are well supported by current browsers.

Column 1
General support for transitions.
Column 2
Support for the property transition-duration which defines the duration of a transition.
1
Transitions
support
2
transition-duration
property
Estimated overall support.
97%
96%

Browsers on computers :

Mobile browsers :

Outdated or marginal browsers :

Internet Explorer

QQ Browser

Safari sur IOS

Firefox pour Androïd

Opéra Mobile

Baidu Browser

KaiOS Browser

UC Browser pour Androïd

Samsung Internet

Chrome

Edge

Firefox

Androïd Brower

Chrome pour Androïd

Opéra

Safari

Opéra mini

Historic of the transition-duration property.

  • CSS Transitions - Level 1

    Normally, when a property changes of value, its display on the screen is immediate. This specification module describes how to progressively change properties from one value to another over a given time. In other words, how to gradually move from one state to another.
    However, an external event is needed to trigger the change in property values (JavaScript code, user action, etc.). In this sense, transitions differ from animations, which can run independently of any external action.

    Regarding transition-duration. First specification defining transitions in CSS.
    And introduction of the transition-duration property.
    WD
    March 20, 2009
    Working Draft.
    CR
    PR
    REC
  • CSS Transitions - Level 2

    Level 2 of the specification on transitions adds the ability to apply a transition to a discrete property.
    A new at-rule @starting-style allows defining the starting values for property values. It is now possible to apply a transition to elements that go from the invisible state to the visible state.

    Regarding transition-duration. No change to the transition-duration property.
    WD
    September 05, 2023
    Working Draft.
    CR
    PR
    REC

See also regarding the transitions.

The W3C publishes standards segmented into modules. Transitions are described in the CSS Transitions. To facilitate your research, here are the other properties related to transitions:

Properties:

transition
Group the different parameters of one or more transitions.
transition-behavior
Defines the behavior of transitions on properties whose animation type is discrete.
transition-delay
Sets the amount of time to wait before the transition begins, counted from the time the property is changed.
Transition-duration
Defines the duration of a transition, i.e. the time it takes to complete its transition.
transition-property
Defines the property(s) on which a transition should be applied.
transition-timing-function
A property that defines the easing function to be used during a transition.

At-rules:

@starting-style
Sets the initial values for properties that will be subject to a transition.