CSS transition-duration Property

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The transition-duration property sets how long a CSS transition takes to finish. The initial value is 0s, so changes are instant until you set a positive time.

Use a <time> in seconds (s) or milliseconds (ms). It is not inherited. Pair it with transition-property (what changes), transition-timing-function (easing), and transition-delay (wait time), or the transition shorthand.

Baseline · Widely available.

Not deprecated. Standard-track CSS. Negative times are invalid. Prefer shorter durations for UI feedback, and respect prefers-reduced-motion when motion can distract.

CSS Syntax

syntax.css
transition-duration: <time> | <time>, <time>, … | initial | inherit;

Examples: transition-duration: 0.3s; · transition-duration: 300ms; · transition-duration: 1s, 200ms;

Property Values

ValueDescriptionTry it
<time> (s)Duration in seconds, such as 0.5s or 2sTry it
<time> (ms)Duration in milliseconds, such as 200msTry it
0sDefault. Instant change (no visible transition)Try it
Multiple timesComma-separated list mapped to transition-propertyTry it
initialResets to 0sTry it
inheritTakes the value from the parent elementTry it

How to Use transition-duration

Pick what changes, then decide how long that change should take.

  1. Choose a property that can transition (for example background-color or transform).
  2. Set transition-property (or use the transition shorthand).
  3. Set transition-duration to a positive time such as 0.25s or 250ms.
  4. Trigger a state change (hover, class toggle, focus) and watch the timed change.
PieceRequired?Role
Transitionable propertyYesSomething must change between two states
Positive durationYes (to see motion)Default 0s is instant
State changeYesHover, focus, class, or media change starts it
Timing / delayOptionalEasing and wait time polish the feel

Live Preview

Hover or focus the box. Only transition-duration changes — longer values take more time to finish.

Hover or focus the blue box. Background and size transition with the selected duration.

Hover / focus

transition-duration: 0.5s

CSS Examples

Each snippet focuses on transition-duration. Other transition pieces are only there so a change can run. Use Try It Yourself for a live editor.

Example 1 — Duration in Seconds

Take half a second to change the background on hover.

CSS
<style>
  button {
    background: #2563eb;
    color: #fff;
    border: 0;
    padding: 12px 16px;
    transition-property: background-color;
    transition-duration: 0.5s;
  }
  button:hover,
  button:focus-visible {
    background: #16a34a;
  }
</style>

<button type="button">Hover me</button>
Try It Yourself

How It Works

  1. Name what changes. transition-property: background-color limits the transition.
  2. Set the length. transition-duration: 0.5s is the lesson — half a second.
  3. Provide two states. Default blue, hover/focus green.
  4. Watch the blend. The color morphs over 0.5s instead of jumping.

Example 2 — Duration in Milliseconds

Use ms for a snappy UI feel.

CSS
<style>
  button {
    background: #2563eb;
    color: #fff;
    border: 0;
    padding: 12px 16px;
    transition-property: background-color;
    transition-duration: 200ms;
  }
  button:hover,
  button:focus-visible {
    background: #16a34a;
  }
</style>

<button type="button">Quick hover</button>
Try It Yourself

How It Works

  1. Same pattern as seconds. Only the time unit changes.
  2. Use milliseconds. 200ms equals 0.2s.
  3. Keep UI short. Buttons often feel best around 150–300ms.
  4. Unit is required. Write 0ms or 0s, never bare 0.

Example 3 — Multiple Durations

Give each transitioning property its own length of time.

CSS
<style>
  button {
    background: #2563eb;
    color: #fff;
    border: 0;
    padding: 12px 16px;
    transition-property: background-color, transform;
    transition-duration: 200ms, 1s;
  }
  button:hover,
  button:focus-visible {
    background: #16a34a;
    transform: translateX(12px);
  }
</style>

<button type="button">Color fast, move slow</button>
Try It Yourself

How It Works

  1. List the properties. transition-property is the master list.
  2. List matching times. First duration pairs with the first property.
  3. Here: color then move. Background uses 200ms; transform uses 1s.
  4. Lists can cycle or truncate. If counts differ, the browser repeats or trims the duration list.

Edge Cases & Pitfalls

If nothing seems to animate, check these first.

0s

Default duration is instant

With 0s, the property still “transitions,” but you will not see motion. Set a positive time to observe it.

units

Time needs a unit

Use 0s or 0ms. Bare 0 is invalid for <time>. Negative values invalidate the declaration.

property

Only some properties interpolate

Duration alone is not enough. The changing property must be transitionable, and a real state change must occur.

lists

Multiple durations follow transition-property

Times map in order to the property list. Too few durations repeat; too many are truncated.

a11y

Respect reduced motion

Long or large motion can distract. Offer a shorter duration (or none) under @media (prefers-reduced-motion: reduce).

Browser Support

transition-duration is a browser CSS property for transition timing. Node.js, Deno, and Bun do not apply it.

✓ Baseline · Widely available

transition-duration

Widely supported across modern browsers since about September 2015. Seconds, milliseconds, and comma-separated lists are standard.

97% Core support
Google Chrome 26+
Full support
Mozilla Firefox 16+
Full support
Apple Safari 9+
Full support
Microsoft Edge 12+
Full support
Opera 12.1+
Full support
Samsung Internet 1.5+
Full support
Internet Explorer 10+
Full support
transition-duration Widely supported

Bottom line: Safe to teach and ship for s/ms durations. Prefer unprefixed standard syntax in modern code. It is not a runtime API.

Key Takeaways

  • Role: set how long a transition takes to complete.
  • Initial value: 0s — no visible animation until you raise it.
  • Units: s or ms only; unitless 0 is invalid.
  • Lists: multiple times map to transition-property in order.

One line: without a positive transition-duration, every transition is instant — set s or ms to make the change visible.

Frequently Asked Questions

It sets how long a CSS transition takes to complete after it starts. The default 0s means the change is instant.
Use <time> values with a unit: seconds (s) or milliseconds (ms). Example: 0.3s or 300ms. Unitless 0 is invalid — write 0s.
transition-duration is how long the change runs. transition-delay is how long to wait before it starts.
Yes. List multiple times separated by commas. They map in order to the properties in transition-property.
No. A negative time makes the declaration invalid.
It is Baseline Widely available across modern browsers. It is a browser CSS property, not a Node.js feature.

Next: transition-property

Learn which CSS properties participate in a transition.

transition-property tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful