CSS Transitions Cheatsheet: Interactive Visual Guide

October 16, 2026  |  Cheatsheet  |  CSS

By Syed · Frontend Engineer & Creator of UITweak

Transitions turn instant state changes into smooth motion. The syntax is short, but picking the right duration and easing is what separates a snappy UI from a sluggish one. Every section below is interactive: click, drag, and feel each value before you copy it.

Prefer building over reading? Open the Button Studio →

Interactive transition builder

Changing a property, duration, timing function, or delay shows how the browser interpolates between the old and new computed values over time. The transition itself is declared on the element's resting state, and the animation runs whenever a style change alters one of the listed properties. Because only the listed properties animate, flipping the property control from all to transform visibly narrows which changes get interpolated.

Click the box to play the transition

property

timing function

Starts fast and decelerates. Good for elements entering the screen, feels responsive and snappy.

.box {
  transition: transform 400ms ease-out 0ms;
}

transition syntax order

The shorthand packs four longhands into one line in this order: property, duration, timing function, delay. The duration is the one required piece; without a time value there is nothing to transition over. When two time values appear, the first is always the duration and the second is always the delay, which is why transition: opacity 200ms ease 100ms reads unambiguously to the parser.

Click each slot to see what it does:

duration

How long the transition takes, in seconds or milliseconds. UI feedback usually feels right between 150ms and 400ms. Anything over a second starts to feel sluggish for hover effects.

/* order: property duration timing-function delay */
transition: transform 300ms ease-out 0ms;

/* multiple properties, comma-separated */
transition: transform 300ms ease-out, opacity 200ms linear;

/* longhands when you need them */
transition-property: transform;
transition-duration: 300ms;
transition-timing-function: ease-out;
transition-delay: 0ms;

Timing function presets

Each preset is a cubic-bezier curve that maps elapsed time to animation progress, so ease-out starts fast and decelerates while ease-in does the opposite. The custom curves in the demo, such as the springy overshoot, show that a bezier can push progress past 100% and settle back, which is how bounce-like motion is faked without keyframes. steps(4) is the odd one out: it jumps between four discrete states with no interpolation at all.

transition-timing-function: cubic-bezier(0.16, 1, 0.3, 1);

Modals, drawers, dropdowns appearing

Common recipes

The recipes here are the same handful of transitions reused across real interfaces: fades, slides, and press effects built from opacity and transform. They stay compositor-friendly on purpose, which is why none of them animate layout properties. Like the rest of the page, the section is a pattern library: learn the underlying mechanism once, then assemble the recipes from memory.

1. Hover lift

Hover me

lifts and gains shadow

2. Color fade on a button

3. Image zoom on hover

<!-- hover lift -->
<div class="transition-all duration-300 ease-out hover:-translate-y-1 hover:shadow-xl">
  hover me
</div>

<!-- color fade -->
<button class="transition-colors duration-200 hover:bg-indigo-600">
  hover me
</button>

<!-- image zoom: scale the inner, clip with the outer -->
<div class="overflow-hidden rounded-2xl">
  <div class="transition-transform duration-500 ease-out hover:scale-110">
    ...
  </div>
</div>

Want full keyframe animations, not just transitions? Try our free CSS Animation Generator with live preview and one-click code export.

Demo Deepening

Common Production Bugs & Fixes

Bug: no transition from `display: none` to `block`

What goes wrong: you toggle a dropdown from display: none to display: block with an opacity transition declared, and it appears instantly with no fade. Why: display is not an interpolable property, and while the element is display: none it has no rendered box at all, so there is no start state to animate from. The classic fix animates opacity together with visibility, delaying the visibility flip until the fade finishes; in browsers that support it, @starting-style plus transition-behavior: allow-discrete handles the entry transition directly.

/* fades both ways without touching display */
.dropdown {
  opacity: 0;
  visibility: hidden;
  transition: opacity 200ms ease, visibility 0ms linear 200ms;
}
.dropdown.open {
  opacity: 1;
  visibility: visible;
  transition: opacity 200ms ease, visibility 0ms;
}

Bug: transitioning to or from `height: auto` does nothing

What goes wrong: you set transition: height 300ms and toggle between height: 0 and height: auto, and the panel snaps open with no animation. Why: auto is not a length, so the browser cannot compute intermediate values between 0 and auto; interpolation needs two concrete numbers. The robust fix is the grid trick, animating grid-template-rows between 0fr and 1fr while the inner content has min-height: 0. Where supported, calc-size(auto, size) lets you interpolate against auto directly.

/* animated expand/collapse without a fixed height */
.accordion {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 300ms ease;
}
.accordion.open { grid-template-rows: 1fr; }
.accordion > div {
  overflow: hidden;
  min-height: 0;
}

Bug: `transition: all` makes unrelated changes animate

What goes wrong: you declare transition: all 300ms on a card, and later a JavaScript-driven class change or a simple :hover color shift animates every property at once, including ones you never intended to move. Why: all subscribes every animatable property to the transition, so any computed-value change anywhere in the rule set gets interpolated, which also costs extra style recalculation. The fix is to list exactly the properties you mean to animate, keeping the transition's scope explicit and cheap.

/* too broad: any property change animates */
.card { transition: all 300ms ease; }

/* explicit: only the intended properties animate */
.card { transition: transform 300ms ease, box-shadow 300ms ease; }

Bug: combined transforms animate along the wrong path

What goes wrong: you transition between transform: translateX(40px) rotate(45deg) and transform: rotate(45deg) translateX(40px) and the element takes a strange curved path instead of moving cleanly. Why: transform functions compose as matrix multiplication applied right to left, so swapping the order changes the resulting matrix and the interpolation follows a different route. The fix is to keep the function list identical and in the same order in both states, changing only the numeric arguments.

/* mismatched order: unpredictable path */
.card { transform: translateX(0) rotate(0deg); transition: transform 300ms ease; }
.card:hover { transform: rotate(45deg) translateX(40px); }

/* matched order: clean interpolation */
.card { transform: translateX(0) rotate(0deg); transition: transform 300ms ease; }
.card:hover { transform: translateX(40px) rotate(45deg); }

Real-World Recipes

Recipe: dropdown that fades and slides in

Animate opacity from 0 to 1 and translateY from -8px to 0 so the menu both appears and settles downward, which reads as emerging from its trigger. Keep visibility in the transition with a delayed flip so the hidden menu is removed from keyboard tab order and cannot be clicked while invisible. Put the transition on the base rule so it also plays in reverse when the menu closes.

.menu {
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition:
    opacity 180ms ease,
    transform 180ms ease,
    visibility 0ms linear 180ms;
}
.menu.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  transition:
    opacity 180ms ease,
    transform 180ms ease,
    visibility 0ms;
}

Recipe: smooth accordion without fixed heights

Wrap the collapsible content in a grid container and animate grid-template-rows between 0fr and 1fr. The inner wrapper needs overflow: hidden and min-height: 0 so it can actually collapse to zero. This animates content of any height with no JavaScript measurement and no magic max-height number that breaks on long content.

.accordion {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 300ms ease;
}
.accordion.open {
  grid-template-rows: 1fr;
}
.accordion > .inner {
  overflow: hidden;
  min-height: 0;
}

Recipe: tactile button press

On hover, lift the button slightly with translateY(-2px) and deepen the shadow; on active, press it down with translateY(0) and shrink the shadow. Declare the transition once on the base rule with a short 150ms duration so the press feels immediate. Because only transform and box-shadow move, the effect stays cheap to render.

.btn {
  transform: translateY(0);
  box-shadow: 0 2px 6px rgb(0 0 0 / 0.15);
  transition: transform 150ms ease, box-shadow 150ms ease;
}
.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 14px rgb(0 0 0 / 0.18);
}
.btn:active {
  transform: translateY(0);
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.15);
}

FAQ

Why does my transition not play when I add the class in the same frame the element is created?

A transition needs a before and an after value, and both must pass through style calculation. If the element is inserted and the class is added synchronously, the browser computes only the final style and there is no change to animate from. Force a style recalculation between the two steps, for example by reading offsetHeight or by adding the class inside requestAnimationFrame, so the initial state is committed first.

How do I make the hover-in and hover-out animations use different timing?

The transition that runs when a state ends is the one declared on the resting rule, not the one in the :hover rule. Put the slow, gentle transition on the base selector and a snappier one inside :hover: entering uses the hover rule's timing, leaving falls back to the base rule's timing. This gives you asymmetric motion with no JavaScript.

Can transitions animate discrete properties like display at all?

In browsers that implement CSS Transitions Level 2, yes, with transition-behavior: allow-discrete. That keyword permits the transition to run on discrete properties by flipping the value at the 50% mark of the timing function, and combined with @starting-style it produces real entry transitions from display: none. Where it is unsupported, the declaration is ignored and the change applies instantly, so keep the opacity and visibility pattern as the safe baseline.

Do transitions respect prefers-reduced-motion on their own?

No. The browser runs declared transitions regardless of the user's motion preference; honoring it is the author's job. Wrap your transitions in a media query that shortens them to near-zero or removes them when prefers-reduced-motion: reduce matches. A common pattern is to set transition-duration: 0.01ms inside the query so state changes still apply instantly without jarring jumps.

Share this guide