CSS transition Property

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

What You’ll Learn

The transition property lets you animate CSS changes smoothly over time — perfect for hover effects, focus states, and polished UI feedback without JavaScript.

01

Shorthand

One line, four parts.

02

Duration

Control speed in seconds.

03

Timing

ease, linear, and more.

04

Delay

Wait before starting.

05

Hover UI

Buttons and cards.

06

Motion safety

Respect user prefs.

Introduction

The transition property in CSS allows you to change property values smoothly over a given duration. It is commonly used to create animations and enhance user interactions by animating the changes of CSS properties. This makes your web pages more dynamic and engaging.

Definition and Usage

Use transition on the base state of an element (not only on :hover) so the browser knows how to animate both directions — when the state changes in and when it changes back.

💡
Beginner Tip

Always include a duration (for example 0.3s). Without it, the default is 0s and you will not see any animation.

📝 Syntax

The transition property is a shorthand for four individual transition properties:

  • transition-property — which CSS property to animate
  • transition-duration — how long the animation takes
  • transition-timing-function — the speed curve
  • transition-delay — wait time before the transition starts
syntax.css
element {
  transition: property duration timing-function delay;
}

Basic Example

transition.css
button {
  transition: background-color 0.5s ease;
}

button:hover {
  background-color: red;
}

Syntax Rules

  • Duration must use time units such as s or ms.
  • Only the first value after the property name is required to be a duration when using shorthand.
  • You can list multiple transitions separated by commas.
  • Set transition on the default state, not only on :hover.
  • The property is not inherited.

Related Properties

  • transition-property — choose which properties animate
  • transition-duration — set animation length
  • transition-timing-function — control acceleration curve
  • transition-delay — delay the start of the transition
  • animation — keyframe-based motion on a timeline

🎯 Default Value

The default value of the transition property is none 0s ease 0s, which means no transition effect will be applied unless specified.

⚡ Quick Reference

QuestionAnswer
Default valuenone 0s ease 0s
Basic hover fadetransition: opacity 0.3s ease;
Transform lifttransition: transform 0.25s ease;
Multiple propertiestransition: width 0.4s, box-shadow 0.4s;
Common timingease, linear, ease-in-out
InheritedNo

💎 Property Values

The shorthand combines four parts. Each part maps to a longhand property.

PartExampleDescription
transition-propertybackground-colorSpecifies the CSS property to animate. Default is all, which applies the transition to every animatable property.
transition-duration0.5sSpecifies how long the transition takes. Default is 0s.
transition-timing-functioneaseSpecifies the speed curve. Common values: ease, linear, ease-in, ease-out, ease-in-out, step-start, step-end.
transition-delay0.2sSpecifies a delay before the transition starts. Default is 0s.
ease linear ease-in ease-out ease-in-out

When to Use transition

transition is ideal when a property changes because of user interaction or a class toggle:

  • Button hover states — Smooth color, shadow, or scale changes on hover and focus.
  • Card interactions — Lift cards with transform instead of animating layout properties.
  • Menu reveals — Fade or slide panels open with opacity and transform.
  • Form focus feedback — Highlight borders and backgrounds when inputs are focused.

👀 Live Preview

Hover the demos below to see smooth transitions in action:

background-color
transform

Examples Gallery

In this example, we’ll change the background color of a button with a smooth transition over 0.5 seconds.

📜 Core Patterns

Start with simple color and size transitions on interactive elements.

Example 1 — Button background color transition

In this example, we’ll change the background color of a button with a smooth transition over 0.5 seconds.

index.html
<style>
  button {
    background-color: blue;
    color: white;
    padding: 10px 20px;
    border: none;
    cursor: pointer;
    transition: background-color 0.5s ease;
  }
  button:hover {
    background-color: red;
  }
</style>

<button>Hover over me!</button>
Try It Yourself

How It Works

The base button sets transition: background-color 0.5s ease. When hover changes the color, the browser animates between blue and red over half a second.

Example 2 — Multiple properties at once

Transition width, height, and box-shadow together for a richer hover effect.

multi.css
.card {
  width: 160px;
  height: 100px;
  transition: width 0.4s ease, height 0.4s ease, box-shadow 0.4s ease;
}

.card:hover {
  width: 200px;
  height: 120px;
  box-shadow: 0 8px 24px rgba(37, 99, 235, 0.25);
}
Try It Yourself

How It Works

Comma-separated transitions let each property share the same duration and easing while animating independently.

📄 UI Patterns

Compare timing curves and combine transition with transform for performant motion.

Example 3 — Timing function comparison

See how ease, linear, and ease-in-out change the feel of the same movement.

timing.css
.ease .bar { transition: transform 1.2s ease; }
.linear .bar { transition: transform 1.2s linear; }
.ease-in-out .bar { transition: transform 1.2s ease-in-out; }

.demo:hover .bar { transform: translateX(120px); }
Try It Yourself

How It Works

The timing function controls acceleration. linear moves at constant speed; ease-in-out starts and ends gently.

Example 4 — Card lift with transform

Prefer transform and box-shadow over width/height for smoother, GPU-friendly hover effects.

card.css
.card {
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.card:hover {
  transform: translateY(-6px) scale(1.03);
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.12);
}
Try It Yourself

How It Works

transform changes do not trigger layout reflow, so the lift animation stays smooth even on lower-end devices.

♿ Accessibility

  • Reduced motion — Wrap or shorten transitions when prefers-reduced-motion: reduce is set.
  • Do not rely on motion alone — Ensure state changes are visible without animation (color, outline, text).
  • Focus states — Apply transitions to :focus-visible so keyboard users get the same polish.
  • Avoid long delays — Delays on essential UI feedback can confuse users who expect instant response.

transition + transform

For hover lifts, scales, and slides, pair transition with transform instead of animating layout properties like top or width when possible.

transform-transition.css
.card {
  transition: transform 0.2s ease;
}
.card:hover {
  transform: scale(1.05);
}

🧠 How transition Works

1

Base state defines transition

Set property, duration, timing, and delay on the element’s default rule.

Setup
2

Property value changes

Hover, focus, or a class toggle updates a CSS property to a new value.

Trigger
3

Browser interpolates

The browser animates from the old value to the new value over the duration.

Animate
=

Smooth visual change

Users see polished motion instead of an instant jump.

Browser Compatibility

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

Modern browsers · Widely supported

CSS transitions everywhere

transition works in current Chrome, Firefox, Safari, Edge, and Opera for hover and state-change animations.

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 hover transitions on touch devices; some browsers do not fire hover until tap, so provide equivalent focus or active states.

transition property 98% supported

Bottom line: transition is safe to use for modern interactive UI polish.

Conclusion

The transition property is a versatile and powerful tool for web developers, enabling the creation of smooth animations and enhancing the user experience.

By specifying transitions for different properties, durations, timing functions, and delays, you can create visually appealing effects that make your web pages more engaging and interactive. Experiment with different combinations and see how the transition property can bring your web projects to life.

💡 Best Practices

✅ Do

  • Set transition on the base element state
  • Include an explicit duration such as 0.3s
  • Prefer transform and opacity for performance
  • Respect prefers-reduced-motion: reduce
  • Style :focus-visible alongside hover

❌ Don’t

  • Forget a duration — default 0s shows no animation
  • Transition every property with all without reason
  • Use very long durations on essential UI feedback
  • Rely on hover-only effects for critical information

Key Takeaways

Knowledge Unlocked

Five things to remember about transition

Use these points when adding motion to your UI.

5
Core concepts
02

Duration

Always set time.

Speed
📈 03

Timing

ease vs linear.

Curve
👁 04

Trigger

Hover or class.

Usage
05

Motion

Respect prefs.

A11y

❓ Frequently Asked Questions

transition smoothly animates changes between two CSS property values over a set duration, such as fading a background color or moving an element on hover.
The default is none 0s ease 0s, which means no transition effect is applied unless you specify one.
transition runs when a property value changes, like on hover. animation runs keyframes on a timeline and can loop without a trigger.
Most animatable properties work, including color, opacity, transform, width, and height. Layout-heavy properties like display are not transition-friendly.
No, transition is not inherited. Set it on each element you want to animate.

Practice in the Live Editor

Open the HTML editor and build smooth hover effects with CSS transition.

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