CSS transition Property

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

Definition and Usage

The transition property is a shorthand for transition-property, transition-duration, transition-timing-function, and transition-delay (plus the newer transition-behavior).

It smooths the change when a property value updates — for example on :hover, :focus, or a class toggle. It is not inherited.

Baseline · Widely available.

Not deprecated. Core transitions are cross-browser since about September 2015. Some pieces (such as allow-discrete) are newer and vary by browser.

Order tip.

Write property duration easing delay. The first time is duration; the second time is delay.

CSS Syntax

syntax.css
transition: property duration easing delay | none | initial | inherit;

One or more single transitions, comma-separated. Example: background-color 0.3s ease 0.1s.

Property Values

Value / patternDescriptionTry it
property durationAnimate one property for a set timeTry it
… easingAdd a timing function such as ease-in-outTry it
… delayWait before the transition startsTry it
MultipleComma-separated transitions for different propertiesTry it
allApply the same timing to every changing propertyTry it
none / initialTurn transitions off or reset the shorthandTry it

How to Use transition

Define the transition on the resting state, then change values on the target state.

  1. Pick an animatable property (opacity, transform, background-color, …).
  2. Set transition on the base rule (not only on :hover).
  3. Change the property on :hover, :focus-visible, or a class.
  4. Prefer short durations (about 150ms–400ms) for UI feedback.

Live Preview

Choose a transition value, then press Toggle (works with keyboard). Watch color and position ease.

Transition is set on the box. Toggle flips the end state so you can compare timings.

Box
Hover / Toggle

transition: background-color 0.4s ease, transform 0.4s ease

CSS Examples

Put transition on the base rule so both enter and leave animate. Use Try It Yourself for a live editor.

Example 1 — Background Color

Smoothly change color when the button is hovered or focused.

CSS
<style>
  .btn {
    background: #2563eb;
    color: #fff;
    transition: background-color 0.4s ease;
  }
  .btn:hover,
  .btn:focus-visible {
    background: #dc2626;
  }
</style>

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

How It Works

  1. Set transition on the base. background-color 0.4s ease defines what and how long.
  2. Change the value on hover/focus. The end color is red.
  3. Browser interpolates. Blue fades toward red over 0.4s.
  4. Leave also animates. Because transition sits on the base rule, both directions ease.

Example 2 — Duration, Easing, and Delay

Full single-property form: wait, then ease the color change.

CSS
<style>
  .btn {
    background: #2563eb;
    color: #fff;
    transition: background-color 0.6s ease-in-out 0.25s;
  }
  .btn:hover,
  .btn:focus-visible {
    background: #16a34a;
  }
</style>

<button class="btn" type="button">Wait, then fade</button>
Try It Yourself

How It Works

  1. Property. Only background-color is transitioned.
  2. Duration. 0.6s is how long the fade lasts.
  3. Easing. ease-in-out starts and ends softly.
  4. Delay. 0.25s waits before the fade begins.

Example 3 — Multiple Properties

Comma-separate transitions so color and transform can use the same timing.

CSS
<style>
  .card {
    background: #2563eb;
    color: #fff;
    transition:
      background-color 0.35s ease,
      transform 0.35s ease;
  }
  .card:hover,
  .card:focus-visible {
    background: #7c3aed;
    transform: translateY(-6px);
  }
</style>

<button class="card" type="button">Lift me</button>
Try It Yourself

How It Works

  1. List two transitions. Separate them with a comma.
  2. Color fades. Background moves toward purple.
  3. Transform lifts. translateY(-6px) moves the box up smoothly.
  4. Prefer transform. It usually animates more smoothly than top/margin.

Edge Cases & Pitfalls

Most “broken” transitions come from where you put the property or what you try to animate.

base-rule

Put transition on the base state

If you only set transition inside :hover, the leave animation often snaps back. Keep it on the resting rule.

duration

Zero duration means no motion

Duration defaults to 0s. Without a positive time, you will not see a transition.

discrete

Not every property interpolates

Values like display are discrete. allow-discrete / transition-behavior can help in modern browsers, but prefer opacity/transform for beginners.

all

Use all carefully

transition: all … is handy for demos, but listing only the properties you need is clearer and often cheaper.

a11y

Respect reduced motion

In real UIs, shorten or disable motion under prefers-reduced-motion: reduce.

Browser Support

transition is a browser CSS property for UI state changes. Node.js, Deno, and Bun do not apply it.

✓ Baseline · Widely available

transition

Chrome 26+, Firefox 16+, Safari 9+, Edge 12+, IE 10+. Widely available since September 2015. Newer longhands like transition-behavior vary.

98% Browser 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 Widely supported

Bottom line: Safe for modern UI polish. Prefer opacity and transform. It is not a runtime API.

Key Takeaways

  • Shorthand: property, duration, easing, delay in one declaration.
  • Needs a change: transition only runs when a value actually changes.
  • Base rule: declare transition on the resting state so both directions animate.
  • vs animation: transition reacts to state; keyframes can loop on a timeline.

One line: use transition on the base rule to smooth property changes between states.

Frequently Asked Questions

It is a shorthand that animates changes between two CSS values over time — for example a background color or transform on hover.
The longhands default to all, 0s, ease, 0s, and normal. With duration 0s, you see no visible transition until you set a duration.
A transition runs when a property value changes (hover, class toggle). An animation uses keyframes and can loop without a state change.
Animatable values such as color, opacity, and transform work well. Discrete properties like display need special handling (allow-discrete) and are not beginner-friendly.
No. Set it on each element you want to animate.
It is Baseline and widely available since about September 2015. It is a browser CSS property, not a Node.js feature. Newer pieces like transition-behavior have narrower support.

Next: transition-delay

Control how long to wait before a transition begins.

transition-delay 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