CSS transition-duration Property

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 4 Examples
Animation & Motion

What You’ll Learn

The transition-duration property controls how long a CSS transition takes — from instant snaps to slow, gradual changes. It is essential for polished hover and state-change effects.

01

Speed

Control animation length.

02

Time units

Seconds and ms.

03

Shorthand

Second value in transition.

04

Fast UI

0.1–0.3s for buttons.

05

Slow FX

1s+ for emphasis.

06

vs delay

Duration ≠ wait time.

Introduction

The transition-duration property in CSS is used to define the length of time that a transition animation takes to complete. It is part of the CSS Transitions module and allows you to control how long an element should take to change from one style to another.

This property can be particularly useful for creating smooth, visually appealing transitions for various user interactions.

Definition and Usage

Set transition-duration alongside transition-property (or use the transition shorthand). Without a positive duration, changes happen instantly because the default is 0s.

💡
Beginner Tip

For buttons and links, try 0.15s to 0.3s. For large panels or background fades, 0.4s to 0.8s often feels natural.

📝 Syntax

The syntax for the transition-duration property is simple. You specify the duration of the transition in seconds (s) or milliseconds (ms).

syntax.css
element {
  transition-duration: time;
}

Here, time represents the duration of the transition.

Basic Example

transition-duration.css
.box {
  transition-property: background-color;
  transition-duration: 2s;
}

.box:hover {
  background-color: red;
}

Syntax Rules

  • Time values must use s (seconds) or ms (milliseconds).
  • Negative values are not allowed.
  • Default is 0s — no visible transition unless you set a positive duration.
  • In the transition shorthand, duration is the second value.
  • The property is not inherited.

Related Properties

  • transition — shorthand for all transition longhands
  • transition-property — which properties animate
  • transition-delay — wait time before the transition starts
  • transition-timing-function — speed curve during the transition
  • animation-duration — duration for @keyframes animations

🎯 Default Value

The default value of the transition-duration property is 0s, meaning no transition effect unless you specify a positive duration.

⚡ Quick Reference

QuestionAnswer
Default value0s
Slow fadetransition-duration: 2s;
Snappy buttontransition-duration: 0.15s;
In shorthandtransition: opacity 0.4s ease;
Millisecondstransition-duration: 300ms;
InheritedNo

💎 Property Values

The transition-duration property accepts positive time values.

ValueExampleDescription
time2s or 200msA positive time value specified in seconds (e.g., 2s) or milliseconds (e.g., 200ms). Negative values are not allowed.
0.15s 0.3s 500ms 2s

When to Use transition-duration

Choose duration based on the element size and interaction type:

  • Buttons and links — Short durations (0.1–0.3s) feel responsive.
  • Cards and panels — Medium durations (0.3–0.5s) for hover lifts and shadows.
  • Large background changes — Longer durations (0.5–1s+) for dramatic fades.
  • Micro-interactions — Very short (0.05–0.15s) for active/pressed states.

👀 Live Preview

Hover the box below — the color change animates over 1.5 seconds:

transition-duration: 1.5s

Notice how the color shift is gradual, not instant.

Examples Gallery

In this example, we’ll apply a transition duration to a div element that changes its background color on hover.

📜 Core Patterns

Set duration as a longhand property or inside the transition shorthand.

Example 1 — Box with 2 second duration

In this example, we’ll apply a transition duration to a div element that changes its background color on hover.

index.html
<style>
  .box {
    width: 100px;
    height: 100px;
    background-color: blue;
    transition-duration: 2s;
  }
  .box:hover {
    background-color: red;
  }
</style>

<div class="box"></div>
Try It Yourself

How It Works

With transition-duration: 2s, the browser takes 2 full seconds to animate from blue to red on hover, and the same time reversing on mouse out.

Example 2 — Fast vs slow comparison

Two boxes with the same hover effect but different durations show how speed affects feel.

compare.css
.fast .bar { transition-duration: 0.2s; }
.slow .bar { transition-duration: 2s; }

.demo:hover .bar { transform: scale(1.3); }
Try It Yourself

How It Works

Same transform, different duration — shorter feels snappy; longer feels cinematic and deliberate.

📄 UI Patterns

Apply practical durations for links, buttons, and everyday interactions.

Example 3 — Duration in the transition shorthand

The second value in transition: property duration timing is the duration.

shorthand.css
.link {
  transition: color 0.6s ease;
}

.link:hover {
  color: #059669;
}
Try It Yourself

How It Works

0.6s in the shorthand is equivalent to transition-duration: 0.6s;.

Example 4 — Quick button feedback

Use a short duration for responsive button hover and an even shorter one on active press.

button.css
.btn {
  transition: background-color 0.15s ease, transform 0.15s ease;
}

.btn:active {
  transition-duration: 0.05s;
}
Try It Yourself

How It Works

UI controls benefit from fast durations. Overriding to 0.05s on :active makes the press feel immediate.

♿ Accessibility

  • Reduced motion — Set transition-duration: 0.01ms or disable transitions when prefers-reduced-motion: reduce is set.
  • Do not slow essential feedback — Form errors and loading states should not use long durations.
  • Focus parity — Apply the same durations on :focus-visible as on hover.
  • Avoid motion sickness — Very long transitions on large areas can disorient some users.

duration vs delay

transition-duration controls how long the animation runs. transition-delay controls how long to wait before it starts. Both use time units but serve different roles.

duration-delay.css
.box {
  transition-property: opacity;
  transition-duration: 0.5s;  /* runs for half a second */
  transition-delay: 0.3s;     /* waits 0.3s before starting */
}

🧠 How transition-duration Works

1

Duration is set

Define how long the transition should run, e.g. 0.3s.

Setup
2

Property value changes

Hover, focus, or a class toggle triggers a new CSS value.

Trigger
3

Browser animates over time

The property interpolates from old to new value for the full duration.

Animate
=

Smooth change at chosen speed

Users see a gradual shift instead of an instant jump.

Browser Compatibility

The transition-duration property is well-supported in modern browsers, including the latest versions of Chrome, Firefox, Safari, Edge, and Opera. It is advisable to test your website across different browsers to ensure compatibility.

Modern browsers · Widely supported

Transition timing everywhere

transition-duration works in current Chrome, Firefox, Safari, Edge, and Opera alongside other transition properties.

98% Browser support
Google Chrome 26+ · Desktop & Mobile
Full support
Mozilla Firefox 16+ · Desktop & Mobile
Full support
Apple Safari 6.1+ · macOS & iOS
Full support
Microsoft Edge 12+ · All versions
Full support
Opera 12.1+ · All versions
Full support

Testing tip

Test duration feel on real devices — what feels fast on desktop may feel too slow on mobile touch interactions.

transition-duration property 98% supported

Bottom line: transition-duration is safe to use for controlling transition speed in modern browsers.

Conclusion

The transition-duration property is an essential tool for web developers looking to create smooth, gradual transitions between different states of an element.

By specifying the duration of these transitions, you can enhance the user experience and add a touch of elegance to your web projects. Experiment with different durations to see how this property can improve the visual dynamics of your website.

💡 Best Practices

✅ Do

  • Use 0.15–0.3s for buttons, links, and small UI elements
  • Always set a positive duration when you want visible motion
  • Pair with transition-property or use the shorthand
  • Test fast vs slow to find the right feel for each component
  • Respect prefers-reduced-motion: reduce

❌ Don’t

  • Leave duration at default 0s and wonder why nothing animates
  • Use multi-second durations on primary interactive controls
  • Confuse duration with delay — they control different timing
  • Use negative time values (they are invalid)

Key Takeaways

Knowledge Unlocked

Five things to remember about transition-duration

Use these points when choosing transition speed.

5
Core concepts
🕐 02

Default 0s

Instant change.

Default
📈 03

s and ms

Time units.

Values
04

UI speed

0.15–0.3s.

Pattern
📚 05

Not delay

Different role.

Compare

❓ Frequently Asked Questions

transition-duration sets how long a CSS transition takes to complete after it starts, controlling the speed of the animation between two property values.
The default is 0s, which means no visible transition unless you specify a positive duration.
Yes. Use seconds like 2s or milliseconds like 200ms. Negative values are not allowed.
transition-duration controls how long the animation runs. transition-delay controls how long to wait before the animation starts.
No, transition-duration is not inherited. Set it on each element that needs a timed transition.

Practice in the Live Editor

Open the HTML editor and experiment with different transition-duration values.

HTML Editor →

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.

5 people found this page helpful