CSS animation-duration Property

Beginner
⏱️ 6 min read
📚 Updated: Jun 2026
🎯 4 Examples
Animations & Timing

What You’ll Learn

The animation-duration property sets how long one full cycle of a CSS animation takes. Shorter durations feel snappy; longer durations feel smooth and relaxed.

01

Animation Speed

Control how long motion lasts.

02

Syntax

Use s or ms time values.

03

Default 0s

No visible animation without duration.

04

Seconds

2s, 3s, 0.8s and more.

05

Milliseconds

500ms, 800ms for fine control.

06

Shorthand

Works inside animation too.

Definition and Usage

The animation-duration CSS property defines the length of time it takes to complete one animation cycle. It does not control when the animation starts — that is handled by animation-delay — but how fast the keyframes play from start to finish.

Use shorter durations for buttons, toggles, and micro-interactions. Use longer durations for hero fades, background color transitions, and decorative motion that should feel calm.

💡
Beginner Tip

If your animation does not appear to run, check that animation-duration is greater than 0s and that you also set animation-name or use the animation shorthand.

📝 Syntax

Set animation-duration with a CSS time value:

syntax.css
selector {
  animation-duration: time;
}

Basic Example

animation-duration.css
.animated-box {
  animation-name: colorChange;
  animation-duration: 3s;
  animation-iteration-count: infinite;
}

Syntax Rules

  • The value must be a valid CSS time: seconds (s) or milliseconds (ms).
  • The initial value is 0s, which means no visible animation unless you set a positive duration.
  • When multiple animations run on one element, use comma-separated durations matching each animation.
  • Duration is the second value in the animation shorthand, after the animation name.
  • Do not confuse duration with delay — duration is how long the animation runs, not how long it waits.

⚡ Quick Reference

QuestionAnswer
Initial value0s
Applies toElements with CSS animations
InheritedNo
AnimatableNo
Common useSetting animation speed and pacing

Default Value

The initial value of animation-duration is 0s. Without a positive duration, the animation completes instantly and usually appears not to run at all.

💎 Property Values

These are the values you will use when controlling animation speed.

ValueExampleMeaning
Secondsanimation-duration: 2s;One cycle takes 2 seconds
Millisecondsanimation-duration: 500ms;One cycle takes half a second
Decimal secondsanimation-duration: 0.8s;One cycle takes eight tenths of a second
initialanimation-duration: initial;Resets to the default value 0s
inheritanimation-duration: inherit;Inherits duration from the parent element
0.5s

A fast pulse cycle completes in half a second, feeling quick and responsive.

Fast animation

Good for buttons, toggles, and small UI feedback.

2s

A medium-duration pulse feels balanced and easy to follow with the eye.

Medium animation

Common choice for cards, banners, and content reveals.

5s

A slow pulse takes five seconds per cycle, creating a calm, relaxed motion.

Slow animation

Useful for background effects and subtle emphasis.

animation-duration vs animation-delay

PropertyControlsExample
animation-durationHow long the animation runsanimation-duration: 3s;
animation-delayHow long before the animation startsanimation-delay: 1s;

👀 Live Preview

This box changes color over 3 seconds per cycle:

The red-to-yellow transition takes 3s with ease-in-out timing and alternates direction each loop.

Examples Gallery

Try animation-duration with a 3-second color change, fast vs slow motion, milliseconds, and shorthand syntax.

📚 Basic Duration

Start by setting how long one animation cycle should take to complete.

Example 1 — Color Change Over 3 Seconds

Animate a box from red to yellow with a 3-second duration.

animation-duration-color.html
<style>
  @keyframes colorChange {
    from { background-color: red; }
    to { background-color: yellow; }
  }
  .animated-box {
    width: 100px;
    height: 100px;
    animation-name: colorChange;
    animation-duration: 3s;
    animation-timing-function: ease-in-out;
    animation-iteration-count: infinite;
  }
</style>

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

How It Works

Each color transition from red to yellow takes exactly 3 seconds because of animation-duration: 3s.

Example 2 — Fast vs Slow Duration

Compare the same animation at 0.5s and 3s to see how duration changes the feel of motion.

animation-duration-compare.css
.fast { animation-duration: 0.5s; }
.slow { animation-duration: 3s; }
Try It Yourself

How It Works

Both boxes use the same keyframes, but the fast box completes each bounce in 0.5s while the slow box takes 3s.

Example 3 — Duration in Milliseconds

Use milliseconds for precise, quick UI animations such as fades and tooltips.

animation-duration-ms.css
.tooltip {
  animation: fadeIn 400ms ease-out forwards;
}
Try It Yourself

How It Works

400ms equals 0.4s. Milliseconds are handy when you need fine-grained timing for short UI effects.

⚡ Shorthand Usage

Set duration directly inside the animation shorthand as the second value.

Example 4 — Duration in the Animation Shorthand

Include the duration after the animation name in one compact declaration.

animation-shorthand-duration.css
.card {
  animation: riseUp 1.2s ease-out both;
}
Try It Yourself

How It Works

In animation: riseUp 1.2s ease-out both, the 1.2s value is the animation duration.

🧠 How animation-duration Works

1

You define keyframes

Create a start state and end state with @keyframes.

Keyframes
2

You set a duration

Choose how many seconds or milliseconds one full cycle should take.

Time value
3

The browser spreads keyframes over that time

A longer duration makes the same motion slower; a shorter duration makes it faster.

Playback speed
=

Controlled pacing

Duration lets you match animation speed to the mood and purpose of your UI.

Universal Browser Support

animation-duration is supported in all modern browsers alongside CSS animations.

Baseline · CSS Animations

Set animation speed in modern browsers

Chrome, Firefox, Safari, Edge, and Opera all support animation-duration with s and ms values.

98% Modern browser support
Google Chrome43+ · Desktop & Mobile
Full support
Mozilla Firefox16+ · Desktop & Mobile
Full support
Apple Safari9+ · macOS & iOS
Full support
Microsoft Edge12+ · Modern versions
Full support
Opera30+ · Modern versions
Full support

Legacy browsers

Very old browsers without CSS animation support also lack animation-duration.

💻
Internet Explorer IE 9 and earlier · No CSS animation support
None
animation-duration property 98% supported

Bottom line: Use animation-duration confidently in modern projects. Keep UI animations short for better usability.

Conclusion

The animation-duration property controls how long one animation cycle takes to complete. It is one of the most important settings for making motion feel fast, smooth, or relaxed.

Start with values like 0.5s for quick UI feedback and 2s to 3s for larger visual effects, then adjust until the pacing feels right.

💡 Best Practices

✅ Do

  • Use short durations (200ms–500ms) for buttons and tooltips
  • Keep hero and page transitions under about 1.5s when possible
  • Match duration to the size of the element being animated
  • Respect prefers-reduced-motion for accessibility
  • Test the same animation at different speeds before shipping

❌ Don’t

  • Leave duration at the default 0s and wonder why nothing moves
  • Confuse duration with delay
  • Use very long durations for essential UI interactions
  • Make every animation on a page slow and heavy
  • Forget that shorthand duration comes right after the animation name

Key Takeaways

Knowledge Unlocked

Five things to remember about animation-duration

Use these points when setting animation speed.

5
Core concepts
🕑02

Default 0s

Must set a positive time.

Default
📝03

s and ms

2s equals 2000ms.

Values
04

Not Delay

Duration is runtime speed.

Compare
📈05

Shorthand #2

Second value in animation.

Syntax

❓ Frequently Asked Questions

The animation-duration property sets how long one complete cycle of a CSS animation takes to play, from start to finish.
The initial value is 0s. Without a positive duration, the animation will not visibly run.
Yes. You can use seconds (s) or milliseconds (ms), such as 2s or 800ms.
animation-duration controls how long the animation runs. animation-delay controls how long the browser waits before starting it.
Yes. Duration is the second value in the shorthand, for example animation: fadeIn 1.5s ease-in-out;

Practice in the Live Editor

Open the HTML editor, change animation-duration, and compare fast and slow motion instantly.

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