Tutorials CSS Transitions
Ch 44 / 60
Chapter 44 Intermediate 10 min read CSS

CSS Transitions

A CSS transition smoothly animates an element between two states — typically triggered by a user action like hover, focus, or a class change. Instead of snapping instantly from state A to state B, the browser interpolates values over a specified duration following a timing curve. Four sub-properties give you complete control: what to animate, how long, how fast/slow at each point, and when to start.

What you'll learn
The 4 transition sub-properties
transition-duration — timing matters
All timing functions + cubic-bezier
transition-delay for staggered effects
Transitioning multiple properties
Real-world UI patterns: buttons, cards, toggles

The transition Property

The transition shorthand takes four values in order. All four are optional — only the duration is commonly required:

transition: transform .3s ease-out .1s;
property
what to animate
duration
how long
timing-function
speed curve
delay
when to start
CSS — transition syntax
/* Shorthand */
.el { transition: property duration timing-function delay; }

/* Examples */
.el { transition: all .3s ease; }            /* all animatable properties */
.el { transition: background .3s ease; }    /* background only */
.el { transition: transform .3s ease-out .1s; }

/* Individual sub-properties */
.el {
  transition-property:       transform, opacity;
  transition-duration:       .3s, .2s;
  transition-timing-function: ease-out, linear;
  transition-delay:          0s, .05s;
}

/* Multiple transitions — comma separated */
.el {
  transition:
    background .3s ease,
    transform  .3s cubic-bezier(.34,1.56,.64,1),
    box-shadow .3s ease;
}

/* IMPORTANT: put transition on BASE state, not :hover */
.btn       { transition: background .3s ease; }  /* ✓ correct */
.btn:hover { transition: background .3s ease; }  /* ✗ only animates on hover, snaps back */

transition-duration — How Long

Duration sets how long the transition takes. Accepts seconds (s) or milliseconds (ms). Human perception is key: 100–300ms feels snappy, 300–600ms feels smooth, over 1s starts feeling slow for UI.

Hover each box — same transform, different duration
100ms
0.1s — snappy
300ms
0.3s — balanced ✓
600ms
0.6s — smooth
1s
1s — slow
2s
2s — very slow
Sweet spot for UI
For most interactive UI elements: 200–300ms is the standard. Fast enough to feel responsive, slow enough to be perceptible. Micro-interactions (button hover) can be 150–200ms. More significant transitions (modals, drawers) can be 300–400ms.

transition-timing-function — The Speed Curve

The timing function controls how fast or slow the animation moves at each point during its duration — not how long it takes. All keyword values are shortcuts for cubic-bezier() curves:

Hover any box — same duration (0.6s), different easing
linear
→
ease (default)
→
ease-in
→
ease-out
→
ease-in-out
→
spring (overshoot)
→
snap
→
bounce
→
Curve shapes (time → progress)
linear
constant speed
ease
fast start, slow end
ease-in
slow start
ease-out
fast start, decel
ease-in-out
slow both ends
spring
overshoot
snap (.2,.8,.2,1)
quick settle
bounce
overshoot both
CSS — timing functions and cubic-bezier
/* Keyword values (shortcuts for cubic-bezier) */
.el { transition-timing-function: linear; }       /* cubic-bezier(0,0,1,1) */
.el { transition-timing-function: ease; }         /* cubic-bezier(.25,.1,.25,1) */
.el { transition-timing-function: ease-in; }      /* cubic-bezier(.42,0,1,1) */
.el { transition-timing-function: ease-out; }     /* cubic-bezier(0,0,.58,1) */
.el { transition-timing-function: ease-in-out; }  /* cubic-bezier(.42,0,.58,1) */
.el { transition-timing-function: step-start; }   /* instant jump at start */
.el { transition-timing-function: step-end; }     /* instant jump at end */

/* custom cubic-bezier(x1, y1, x2, y2) */
.spring   { transition-timing-function: cubic-bezier(.34,1.56,.64,1); }  /* overshoot */
.snap     { transition-timing-function: cubic-bezier(.2,.8,.2,1); }     /* fast snap */
.gentle   { transition-timing-function: cubic-bezier(.4,0,.2,1); }     /* Material Design */
.decelerate{ transition-timing-function: cubic-bezier(0,0,.2,1); }    /* elements entering screen */
.accelerate{ transition-timing-function: cubic-bezier(.4,0,1,1); }    /* elements leaving screen */

/* Tool: https://cubic-bezier.com for visual editor */

transition-delay — When to Start

transition-delay waits before starting the transition. Staggering delays on sibling elements creates a cascading wave effect without JavaScript:

Hover the row — each item has +0.1s more delay
Item 1
Item 2
Item 3
Item 4
Item 5
Negative delay — start mid-animation
A negative delay like transition-delay: -.3s starts the transition already 0.3s into its progress. Useful for making a long transition appear to start from a mid-point instantly.
CSS — transition-delay and stagger
/* Basic delay */
.el { transition: transform .3s ease .15s; }  /* wait 0.15s then animate */

/* Stagger — different delay per item */
.item          { transition: transform .3s ease, opacity .3s ease; }
.item:nth-child(1){ transition-delay: 0s; }
.item:nth-child(2){ transition-delay: .1s; }
.item:nth-child(3){ transition-delay: .2s; }
.item:nth-child(4){ transition-delay: .3s; }

/* Negative delay — start already mid-transition */
.el { transition: transform 1s ease -.3s; }

/* Asymmetric — different on hover vs leave */
.tooltip       { transition: opacity .2s ease .5s; }    /* show after 0.5s */
.tooltip.visible{ transition: opacity .2s ease 0s; }    /* hide immediately */

Transitioning Multiple Properties

You can transition different properties at different speeds and with different easings in a single declaration. Use all as a shortcut — but it's less efficient and harder to control:

Hover — background, transform, border-radius and box-shadow all transition independently
Hover me
transition:
  background .3s ease,
  transform  .3s spring,
  border-radius .3s ease,
  box-shadow .3s ease;
CSS — multiple transitions and transition: all
/* Multiple specific transitions */
.card {
  transition:
    background    .3s ease,
    transform     .3s cubic-bezier(.34,1.56,.64,1),
    box-shadow    .3s ease,
    border-color  .2s ease;
}
.card:hover {
  background:   #264de4;
  transform:    translateY(-6px) scale(1.02);
  box-shadow:   0 12px 28px rgba(38,77,228,.3);
  border-color: #264de4;
}

/* transition: all — handy shortcut but broad */
.btn { transition: all .25s ease; }
/* ⚠ all includes width, height, font-size — may cause
   unexpected layout transitions. Be specific when possible */

/* Different duration per property */
.link {
  transition:
    color         .15s ease,        /* fast color change */
    transform     .3s ease-out;      /* slower movement */
}

/* Reduced motion — always handle */
@media (prefers-reduced-motion: reduce) {
  * { transition-duration: .01ms !important; }
}

Real-World UI Patterns

These are the most common CSS transition patterns used in production UI. Hover each element to see the transition:

Buttons
Links & nav
Underline expand →
Cards & interactive elements
Card hover
translateY + shadow + border

Transition Property Reference

Property Values Default
transition-property all, property name, none all
transition-duration 0s, 200ms, .3s… 0s
transition-timing-function ease, linear, ease-in, ease-out, ease-in-out, cubic-bezier(), steps() ease
transition-delay 0s, .1s, negative values… 0s
transition (shorthand) property duration timing delay (comma-separated for multiple) —
Properties that cannot be transitioned

Not all properties are animatable. Properties with discrete values (like display, visibility, position, font-family) cannot interpolate — they snap instantly. CSS Level 4 introduces transition-behavior: allow-discrete that lets you transition between discrete values (including display: none ↔ block), enabling proper enter/exit animations without JavaScript.

Free Resource
CSS3 Cheat Sheet — All Properties & Transitions
Complete reference covering all CSS transition properties, easing functions and UI patterns.
Download PDF

Try It Yourself

All transition patterns in one editor — hover each element to see them live, and experiment by changing values:

Live Editor
✎ Editor
👁 Preview
Featured Course — Enroll Now
Modern Web Development With AI
Master HTML, CSS, JavaScript, React and Node.js with real projects and placement support.
120+
Chapters
40 hrs
Content
10 Real
Projects
4.9 ⭐
Rating
HTML5CSS3JavaScriptReact.jsNode.jsTailwind CSSAI Tools

Quick Check — Chapter 44

Questions & Answers
When a transition is only on :hover, the forward animation (entering hover) is smooth but the reverse animation (leaving hover) snaps instantly — because when the mouse leaves, the :hover state is removed and with it the transition rule, so the browser has no transition to apply on the way back.

When the transition is on the base state, it applies in both directions: the property smoothly interpolates whether the state is being entered or exited.

Example:
.btn { transition: background .3s ease; } — smooth both ways ✓
.btn:hover { transition: background .3s ease; } — smooth hover-in, snap hover-out ✗

Exception: you can deliberately use different transitions for enter vs exit by defining transitions on both:
.btn { transition: background .5s ease; } — slow exit
.btn:hover { transition: background .2s ease; } — fast enter
All three describe different speed profiles:

ease-in — starts slow, ends fast (accelerates). Like a car pulling away from a stop. Feels like the element is "reluctant" to move, then rushes to its destination. Works well for elements leaving the screen.

ease-out — starts fast, ends slow (decelerates). Like a car braking to a stop. Feels natural and snappy for elements entering the screen or responding to user input. The most natural-feeling easing for UI interactions.

ease-in-out — starts slow, reaches peak speed in the middle, ends slow. Symmetric ease. Good for elements that move from one position to another and need to feel balanced and deliberate (like sliding panels).

In practice, ease-out or ease-in-out are most commonly used for UI interactions. Pure ease-in rarely feels right for hover effects because the initial slow start makes the UI feel unresponsive.
cubic-bezier(x1, y1, x2, y2) defines a speed curve using two control points in a unit square where (0,0) is start and (1,1) is end:

— x1, y1: position of the first control point (affects start of curve)
— x2, y2: position of the second control point (affects end of curve)

Key rules: x1 and x2 must be between 0 and 1 (they control time, which can't go backwards). y1 and y2 can go outside 0–1, which creates overshoot effects.

Common values:
— cubic-bezier(0,0,1,1) = linear
— cubic-bezier(.25,.1,.25,1) = ease
— cubic-bezier(.34,1.56,.64,1) = spring (y2=1.56 overshoots then settles)
— cubic-bezier(.4,0,.2,1) = Material Design standard easing

Use cubic-bezier.com to visually design and test custom curves.
CSS stagger uses transition-delay with different values on sibling elements. Each element has the same transition duration and easing, but starts progressively later:

.item { transition: transform .3s ease, opacity .3s ease; }
.item:nth-child(1) { transition-delay: 0s; }
.item:nth-child(2) { transition-delay: .08s; }
.item:nth-child(3) { transition-delay: .16s; }
.item:nth-child(4) { transition-delay: .24s; }

Trigger it by changing state on the parent: .parent:hover .item { transform: translateY(0); opacity: 1; }

This creates a wave effect where items cascade in succession. The stagger interval (the difference between delays) controls how pronounced the cascade looks — 50–100ms per item is typical.
Both animate CSS properties over time, but they serve different purposes:

Transitions:
— Animate between two states (A → B)
— Require a trigger (hover, focus, class change, JS)
— One step — start value and end value
— Cannot loop on their own
— Simpler syntax: just transition: property duration easing
— Best for: hover effects, state changes, interactive UI

Animations (@keyframes):
— Define multiple states (A → B → C → D…)
— Run automatically — no trigger needed
— Can loop indefinitely
— Can play forward, backward, alternate
— Can be paused, delayed, run a set number of times
— Best for: loaders, decorative motion, background effects, on-load animations

Rule of thumb: if an animation happens because the user did something → transition. If it plays on its own → @keyframes animation.
Multiple Choice Questions
Question 1 of 5
Which transition declaration causes a smooth animation on hover but snaps back instantly when the mouse leaves?
Question 2 of 5
What does a cubic-bezier(.34, 1.56, .64, 1) timing function produce?
Question 3 of 5
In the shorthand transition: transform .4s ease-out .2s, what does .2s control?
Question 4 of 5
Which approach is most correct for creating a CSS stagger effect?
Question 5 of 5
Which CSS property cannot be transitioned because it has discrete (non-numeric) values?
Chapter Summary
  • transition shorthand: transition: property duration timing delay. Put on the base state — not :hover — so the animation runs both ways.
  • transition-property: specify which property to animate. Use all as a shortcut but be cautious — it catches layout-triggering properties too.
  • transition-duration: 100–300ms feels snappy for micro-interactions. 300–500ms for larger state changes. Over 600ms starts feeling slow.
  • Timing functions: ease (default), ease-out (most natural for UI entering), ease-in-out (balanced). Custom: cubic-bezier(.34,1.56,.64,1) for spring effects.
  • transition-delay: stagger items by incrementing delay (0s, .08s, .16s…). Negative delay starts mid-animation.
  • Multiple transitions: comma-separate for independent easing per property: transition: background .3s ease, transform .3s cubic-bezier(…).
  • Discrete properties: display, visibility can't interpolate. Use opacity + pointer-events or the new transition-behavior: allow-discrete.
  • Reduced motion: always wrap transitions in @media (prefers-reduced-motion: reduce) to disable for accessibility.
  • Transitions vs animations: transitions need a trigger and animate between 2 states. @keyframes animations run independently and support looping and multi-step sequences.
~10 min read
Intermediate level
Chapter 44 of 60

Rate Us on Google

4.8 / 5
Enjoying this tutorial?
Your 5-star review helps other learners discover our free tutorials and encourages us to keep creating quality content.
80+ reviews
Write a Google Review
Join WhatsApp Channel