CSS transition-duration Property

The CSS transition-duration property specifies how long a CSS transition takes to complete after it begins.

Transition durations use seconds (s) or milliseconds (ms). A longer duration produces a slower change, while a shorter duration produces a faster change. Multiple durations can be assigned to different properties using comma-separated values.

transition-duration Syntax

The transition-duration property accepts one or more non-negative CSS time values. Values can be written in seconds or milliseconds.

Basic Syntax

.example {
  transition-duration: 0.5s;
}

Using Seconds

.example {
  transition-duration: 1s;
}

Using Milliseconds

.example {
  transition-duration: 250ms;
}

Zero Duration

.example {
  transition-duration: 0s;
}

Multiple Durations

.example {
  transition-duration: 0.2s, 0.4s, 0.6s;
}

CSS-Wide Keywords

.example {
  transition-duration: initial;
}
.example {
  transition-duration: inherit;
}
.example {
  transition-duration: unset;
}
.example {
  transition-duration: revert;
}
.example {
  transition-duration: revert-layer;
}

Invalid Examples

.example {
  transition-duration: -0.5s;
}
.example {
  transition-duration: 300;
}
.example {
  transition-duration: 50%;
}
.example {
  transition-duration: 2px;
}
.example {
  transition-duration: 0.2s 0.5s;
}

Negative durations, percentages, lengths, and unitless nonzero numbers are invalid. Multiple duration values must be separated by commas.

Property Values

Value Description
0s Sets the duration to zero. This is the initial value.
0.2s Sets the transition duration to 0.2 seconds.
500ms Sets the transition duration to 500 milliseconds.
1s Sets the transition duration to one second.
0.2s, 0.5s Specifies separate durations for multiple transitions.

Property Characteristics

Characteristic Value
Initial value 0s
Inherited No
Applies to All elements, including ::before and ::after
Computed value As specified
Animation type Not animatable
Percentages Not accepted
Negative values Not allowed
Specification CSS Transitions Level 1

Note: The transition-duration property is a longhand component of the transition shorthand. It specifies the length of a transition, not the delay before it starts.

How It Works

A CSS transition occurs when an eligible property changes from one value to another and the element has a transition configured for that property.

Step 1: Define the Initial Style

.button {
  background-color: #2563eb;
}

Step 2: Select the Transition Property

.button {
  transition-property: background-color;
}

Step 3: Set the Duration

.button {
  transition-duration: 0.4s;
}

Step 4: Define the Changed State

.button:hover {
  background-color: #1e40af;
}

Complete Example

.button {
  background-color: #2563eb;
  transition-property: background-color;
  transition-duration: 0.4s;
  transition-timing-function: ease;
}
.button:hover {
  background-color: #1e40af;
}

Understanding the Result

When the pointer enters the button, the background color transitions from blue to dark blue over 0.4 seconds. When the pointer leaves, the color transitions back over the same duration if the transition is not interrupted.

Important Consideration

The duration controls the transition's timeline. The timing function determines how progress is distributed throughout that timeline.

Seconds and Milliseconds

CSS transition durations use the time units s and ms.

Seconds

.example {
  transition-duration: 1s;
}

One second equals 1,000 milliseconds.

Milliseconds

.example {
  transition-duration: 500ms;
}

Five hundred milliseconds equals half a second.

Equivalent Values

Seconds Milliseconds
0.1s 100ms
0.2s 200ms
0.3s 300ms
0.5s 500ms
1s 1000ms
2s 2000ms

Mixing Units

.example {
  transition-duration: 200ms, 0.5s, 1s;
}

Different time units can appear in the same comma-separated list.

Recommended Practice

Use whichever unit makes the duration easiest to read. Short interface transitions are often expressed in milliseconds, while longer effects may be clearer in seconds.

Zero Transition Duration

The value 0s specifies that a transition has no duration.

Basic Example

.example {
  transition-duration: 0s;
}

Immediate Property Change

.button {
  background-color: #2563eb;
  transition: background-color 0s;
}
.button:hover {
  background-color: #1e40af;
}

The background color changes without gradual interpolation.

Zero Duration With a Delay

.button {
  transition: background-color 0s linear 0.5s;
}

Although the duration is zero, the positive delay can postpone the change. The browser applies the new value after the delay without a gradual transition.

Removing a Transition

.button {
  transition-duration: 0s;
}

Setting the duration to zero removes the visible interpolation, but other transition settings may remain in effect.

Using transition: none

.button {
  transition: none;
}

The none value disables CSS transitions for the element.

Important Consideration

A zero duration does not necessarily mean a zero delay. Check both properties when an element appears to change later than expected.

Multiple Transition Durations

When an element transitions several properties, each property can use a different duration.

Two Properties

.example {
  transition-property: opacity, transform;
  transition-duration: 0.2s, 0.5s;
}

Opacity transitions over 0.2 seconds, while the transform takes 0.5 seconds.

Three Properties

.example {
  transition-property: opacity, transform, background-color;
  transition-duration: 0.2s, 0.4s, 0.6s;
}

Using One Duration for Multiple Properties

.example {
  transition-property: opacity, transform;
  transition-duration: 0.3s;
}

Both properties use the same duration.

Repeating Duration Values

.example {
  transition-property: opacity, transform, background-color;
  transition-duration: 0.2s, 0.5s;
}

The duration list repeats as needed. Opacity uses 0.2 seconds, transform uses 0.5 seconds, and background color uses 0.2 seconds.

Extra Duration Values

.example {
  transition-property: opacity, transform;
  transition-duration: 0.2s, 0.5s, 1s;
}

The extra duration does not create another transition because only two properties are listed.

Multiple Transitions With Shorthand

.example {
  transition: opacity 0.2s ease, transform 0.5s ease-out;
}

Recommended Practice

Keep corresponding transition values in the same order so that durations, delays, and timing functions are easy to match with their properties.

Duration vs. Delay

The transition-duration and transition-delay properties control different parts of a transition.

Property Purpose
transition-duration Specifies how long the transition takes.
transition-delay Specifies how long to wait before starting the transition.

Duration Without Delay

.example {
  transition-duration: 0.5s;
  transition-delay: 0s;
}

The transition begins without waiting and runs for 0.5 seconds.

Duration With Positive Delay

.example {
  transition-duration: 0.5s;
  transition-delay: 0.3s;
}

The transition waits 0.3 seconds and then runs for 0.5 seconds.

Duration With Negative Delay

.example {
  transition-duration: 0.5s;
  transition-delay: -0.2s;
}

The transition begins as though 0.2 seconds have already elapsed, leaving approximately 0.3 seconds before completion.

Timeline Comparison

Duration Delay Behavior
0.5s 0s Starts immediately and finishes after 0.5 seconds.
0.5s 0.3s Starts after 0.3 seconds and finishes after 0.8 seconds.
0.5s -0.2s Starts partway through and finishes after approximately 0.3 seconds.

These timings assume the property value remains unchanged long enough for the transition to finish.

Duration and Timing Functions

The duration specifies the total transition time, while the timing function controls how the property progresses during that time.

Linear Timing

.example {
  transition: transform 1s linear;
}

The transition progresses at a constant rate.

Ease Timing

.example {
  transition: transform 1s ease;
}

The transition starts slowly, speeds up, and slows again near the end.

Ease-In Timing

.example {
  transition: transform 1s ease-in;
}

The transition begins slowly and accelerates.

Ease-Out Timing

.example {
  transition: transform 1s ease-out;
}

The transition begins quickly and slows toward the end.

Ease-In-Out Timing

.example {
  transition: transform 1s ease-in-out;
}

The transition accelerates and decelerates more symmetrically.

Comparing Durations

.fast {
  transition: transform 0.2s ease;
}
.slow {
  transition: transform 1s ease;
}

Both transitions use the same timing function, but the second takes longer to finish.

Important Consideration

Changing the timing function does not change the declared duration. It changes the rate of progress within that duration.

Using the transition Shorthand

The transition-duration property is included in the transition shorthand.

Longhand Syntax

.example {
  transition-property: opacity;
  transition-duration: 0.5s;
  transition-timing-function: ease;
  transition-delay: 0.2s;
}

Equivalent Shorthand

.example {
  transition: opacity 0.5s ease 0.2s;
}

Duration Only

.example {
  transition: opacity 0.5s;
}

Duration and Timing Function

.example {
  transition: opacity 0.5s ease-in-out;
}

Duration and Delay

.example {
  transition: opacity 0.5s 0.2s;
}

The first time value represents duration. The second represents delay.

Multiple Properties

.example {
  transition: opacity 0.3s ease, transform 0.6s ease-out;
}

Shorthand Reset Behavior

.example {
  transition-duration: 1s;
  transition: opacity 0.3s ease;
}

The shorthand replaces the previously declared duration with 0.3s.

Correct Declaration Order

.example {
  transition: opacity 0.3s ease;
  transition-duration: 1s;
}

The later longhand declaration overrides the duration set by the shorthand.

Recommended Practice

Use the shorthand for concise transition definitions. Use the longhand when adjusting duration separately from the other transition settings.

Interrupted Transitions

CSS transitions do not always run for their entire declared duration. A transition may be interrupted when its target property changes again.

Basic Hover Transition

.button {
  background-color: #2563eb;
  transition: background-color 1s ease;
}
.button:hover {
  background-color: #1e40af;
}

Leaving Before Completion

If the pointer leaves the button after 0.3 seconds, the transition may reverse before reaching its original target value.

Reversing Transitions

When a transition reverses, the browser can shorten the reverse transition based on how far the original transition progressed.

Changing Duration Between States

.button {
  transition: background-color 0.3s ease;
}
.button:hover {
  transition-duration: 0.8s;
}

The transition entering the hover state uses the hover duration. Returning to the base state uses the base transition settings, subject to transition reversal rules.

JavaScript State Changes

.panel {
  opacity: 1;
  transition: opacity 0.5s ease;
}
.panel.is-hidden {
  opacity: 0;
}

Rapidly adding and removing the is-hidden class can interrupt and reverse the opacity transition.

Important Consideration

The declared duration describes the full transition. An interrupted or reversing transition may finish sooner.

The transition-duration property works with the other CSS transition longhand properties.

transition

.example {
  transition: opacity 0.4s ease;
}

Combines transition settings into a shorthand declaration.

transition-property

.example {
  transition-property: opacity;
}

Identifies the properties that should transition.

transition-delay

.example {
  transition-delay: 0.2s;
}

Specifies when a transition begins.

transition-timing-function

.example {
  transition-timing-function: ease-in-out;
}

Controls how transition progress changes over time.

transition-behavior

.example {
  transition-behavior: allow-discrete;
}

Allows eligible discrete property changes to participate in transitions.

Complete Example

.example {
  transition-property: opacity, transform;
  transition-duration: 0.3s, 0.6s;
  transition-timing-function: ease, ease-out;
  transition-delay: 0s, 0.1s;
  transition-behavior: normal;
}

Inheritance

The transition-duration property is not inherited. Child elements do not automatically use their parent's transition duration.

Parent Element

.parent {
  transition-duration: 0.5s;
}

Child Element

.child {
  transition-duration: 0.2s;
}

Explicit Inheritance

.child {
  transition-duration: inherit;
}

Restore the Initial Value

.child {
  transition-duration: initial;
}

This restores the initial value of 0s.

Using unset

.child {
  transition-duration: unset;
}

Because the property is not inherited, unset restores its initial value.

Important Consideration

Declare transition durations on the elements whose transitions need to be controlled.

Practical Examples

Button Background Color

.button {
  background-color: #2563eb;
  transition: background-color 0.2s ease;
}
.button:hover {
  background-color: #1e40af;
}

Card Movement

.card {
  transform: translateY(0);
  transition: transform 0.3s ease-out;
}
.card:hover {
  transform: translateY(-5px);
}

Image Opacity

.image {
  opacity: 0.7;
  transition: opacity 0.4s ease;
}
.image:hover {
  opacity: 1;
}

Expandable Panel

.panel {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.5s ease;
}
.panel.is-open {
  max-height: 300px;
}

This approach uses a fixed maximum height. Its visible expansion time may differ from the declared duration when the content is shorter than that maximum.

Multiple Property Durations

.card {
  opacity: 0.8;
  transform: scale(1);
  transition: opacity 0.2s ease, transform 0.5s ease;
}
.card:hover {
  opacity: 1;
  transform: scale(1.03);
}

Navigation Underline

.nav-link {
  text-decoration-color: transparent;
  transition: text-decoration-color 0.25s ease;
}
.nav-link:hover,
.nav-link:focus-visible {
  text-decoration-color: currentColor;
}

Delayed Transition With Duration

.tooltip {
  opacity: 0;
  transition: opacity 0.2s ease 0.3s;
}
.tooltip.is-visible {
  opacity: 1;
}

Reduced Motion Alternative

@media (prefers-reduced-motion: reduce) {
  .animated-element {
    transition: none;
  }
}

transition-duration Example

This example compares three transition durations. Hover over or keyboard-focus each button to see how quickly its background color changes.

HTML Example

<div class="duration-demo">
  <button class="duration-button duration-fast" type="button">0.2 Seconds</button>
  <button class="duration-button duration-medium" type="button">0.6 Seconds</button>
  <button class="duration-button duration-slow" type="button">1.2 Seconds</button>
</div>

CSS Example

.duration-demo {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 15px;
  padding: 20px;
}
.duration-button {
  min-width: 125px;
  padding: 12px 18px;
  border: 0;
  border-radius: 4px;
  background-color: #2563eb;
  color: #fff;
  font: inherit;
  cursor: pointer;
  transition-property: background-color;
  transition-timing-function: linear;
}
.duration-button:hover,
.duration-button:focus-visible {
  background-color: #1e40af;
}
.duration-button:focus-visible {
  outline: 3px solid #f59e0b;
  outline-offset: 3px;
}
.duration-fast {
  transition-duration: 0.2s;
}
.duration-medium {
  transition-duration: 0.6s;
}
.duration-slow {
  transition-duration: 1.2s;
}
@media (prefers-reduced-motion: reduce) {
  .duration-button {
    transition: none;
  }
}
Browser Result

Understanding the Results

All three buttons transition between the same background colors and use the same linear timing function. Only their durations differ.

Fast Transition

The first button completes its color transition in 0.2 seconds.

Medium Transition

The second button completes its color transition in 0.6 seconds.

Slow Transition

The third button takes 1.2 seconds to complete its color transition.

Experiment With Zero Duration

.duration-fast {
  transition-duration: 0s;
}

The background color changes immediately without gradual interpolation.

Experiment With Milliseconds

.duration-medium {
  transition-duration: 600ms;
}

This is equivalent to 0.6s.

Experiment With a Timing Function

.duration-slow {
  transition-duration: 1.2s;
  transition-timing-function: ease-in-out;
}

The duration remains 1.2 seconds, but the rate of color change varies throughout the transition.

Accessibility Considerations

Transition durations influence how quickly users perceive visual changes. Keep effects clear, responsive, and compatible with user preferences.

Respect Reduced Motion Preferences

@media (prefers-reduced-motion: reduce) {
  .interactive-element {
    transition: none;
  }
}

Avoid Excessively Long Transitions

Long transitions can delay visual feedback and make interfaces feel unresponsive.

Maintain Visible Focus Indicators

Keyboard focus indicators should appear promptly and remain clearly visible.

Avoid Unnecessary Motion

Use movement and scaling effects only when they improve the interface. Avoid excessive motion that distracts from content.

Keep Essential Information Available

Do not require users to wait for a lengthy transition before accessing important content or controls.

Support Multiple Input Methods

Interactive effects should work appropriately with keyboard, mouse, and touch input.

Use Clear State Changes

Ensure that the final state remains understandable even when transitions are disabled.

Provide Functional Fallbacks

The interface should remain usable when CSS transitions are unsupported or reduced motion settings remove the effects.

Common Mistakes

Using a Negative Duration

.example {
  transition-duration: -0.5s;
}

Negative transition durations are invalid. Use a non-negative time value.

Omitting Time Units

.example {
  transition-duration: 300;
}

Use a valid time value such as 300ms.

Using Percentages

.example {
  transition-duration: 50%;
}

Percentages are not valid transition duration values.

Confusing Duration With Delay

The duration controls how long the transition lasts. The delay controls when it begins.

Expecting a Transition Without a Property Change

A duration alone does not create an effect. An eligible property value must change.

Forgetting transition-property

The initial transition-property value is all, but specifying the intended properties makes the transition behavior clearer.

Forgetting Commas

.example {
  transition-duration: 0.2s 0.5s;
}

Separate multiple duration values with commas.

Overwriting Duration With the Shorthand

.example {
  transition-duration: 1s;
  transition: opacity 0.3s ease;
}

The shorthand replaces the duration with 0.3s.

Expecting Every Transition to Finish

Transitions can be interrupted, canceled, or reversed when property values change again.

Using Excessively Long Durations

Long transitions can make routine interactions feel slow.

Ignoring Reduced Motion Preferences

Provide an alternative that removes or reduces unnecessary motion.

Important Considerations

Keep the following points in mind when using transition-duration:

  • The property specifies how long a CSS transition takes.
  • The initial value is 0s.
  • The property is not inherited.
  • Values use seconds (s) or milliseconds (ms).
  • Negative durations are invalid.
  • Zero duration removes gradual interpolation.
  • A positive delay can still postpone a zero-duration change.
  • The property accepts comma-separated duration lists.
  • Each duration corresponds to a transition property.
  • Shorter duration lists repeat values as needed.
  • Extra duration values do not create additional transitions.
  • The property is a longhand component of transition.
  • The first time value in the shorthand represents duration.
  • The second time value represents delay.
  • The shorthand resets previously declared transition components.
  • Duration and delay control different parts of the transition timeline.
  • Timing functions control the rate of progress within the duration.
  • Different properties can use different durations.
  • Transitions require eligible property value changes.
  • Interrupted transitions may finish sooner than their declared duration.
  • Reversing transitions can use shortened timing.
  • Long durations can reduce perceived responsiveness.
  • Essential feedback should appear promptly.
  • Respect reduced motion preferences.
  • Test transitions across supported browsers and input methods.

Browser Support

The CSS transition-duration property is widely supported across modern browsers. It is part of the established CSS Transitions feature set and supports seconds, milliseconds, zero durations, and comma-separated duration lists.

For current compatibility information, visit Can I Use? and search for transition-duration.

Basic Declaration

.example {
  transition-duration: 0.3s;
}

Milliseconds

.example {
  transition-duration: 300ms;
}

Multiple Durations

.example {
  transition-duration: 0.2s, 0.4s, 0.6s;
}

Feature Detection

@supports (transition-duration: 0.3s) {
  .example {
    transition-duration: 0.3s;
  }
}

Testing Recommendations

Test transitions with different durations, timing functions, delays, and interrupted state changes. Actual rendering smoothness may vary depending on browser performance, device capabilities, and the properties being transitioned.

Specifications

The transition-duration property is defined in the CSS Transitions Level 1 specification.

CSS Transitions Level 1 - The transition-duration Property

The specification defines valid duration values, how multiple durations correspond to transition properties, and how duration contributes to the transition timeline.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: transition-duration