Color scheme

Transitions

Motion is one of the most powerful tools in a UI designer's kit, and one of the easiest to misuse. A well-placed transition tells users something changed, guides their attention, and makes an interface feel polished and alive. A poorly placed one slows people down, distracts them, or causes physical discomfort. CSS transitions are the entry point to intentional motion: they animate a property from one value to another whenever that property changes, giving you precise control over what moves, how fast, and with what rhythm.

This activity covers the mechanics of the transition shorthand, timing functions and easing curves, multi-property transitions, delays, and the prefers-reduced-motion media query. It is a pattern you will apply in this unit's assignment and carry through every motion-related project going forward.

How Transitions Work

A CSS transition watches a property for changes. When the property's value changes (because of a pseudo-class like :hover, a class toggle via JavaScript, or a state change like :focus), the browser interpolates smoothly between the old and new values over a defined duration, rather than snapping instantly.

Not every CSS property can be transitioned. A property must be interpolatable, meaning the browser can calculate meaningful in-between values. Numeric values like opacity, transform, color, and width are interpolatable. Discrete properties like display or visibility are not interpolatable and switch instantly with no in-between state. A common gotcha: you cannot transition display: none to display: block. If you need to fade something in or out, keep the element in the layout and transition opacity instead, or combine opacity with visibility.

The Four Sub-properties

The transition shorthand combines four individual properties. Understanding each one separately makes the shorthand much easier to read and write correctly.

  • transition-property: Which CSS property to watch. Use a specific property name like opacity or transform rather than the all keyword. The keyword all is convenient but dangerous: it watches every animatable property, which can produce unexpected motion and creates a performance problem because the browser must check all properties on every frame.
  • transition-duration: How long the transition takes, in seconds (s) or milliseconds (ms). UI transitions are typically short: 150ms to 400ms for most interactions. Longer durations work for elaborate entrance animations but feel sluggish for a hover state.
  • transition-timing-function: The easing curve that controls how the property accelerates and decelerates over the duration. Covered in detail in the next section.
  • transition-delay: How long the browser waits before starting the transition. Useful for sequencing multiple properties or for intentional pauses that make motion feel more natural.

Shorthand Syntax

The shorthand order is: property, duration, timing function, delay. The duration must come before the delay. If only one time value is present, it is always treated as the duration.


    /* Single property transition */
    .button {
        transition: background-color 200ms ease-out;
    }

    /* With a delay */
    .tooltip {
        transition: opacity 150ms ease 100ms;
    }
Always Name the Property

Prefer transition: opacity 200ms ease over transition: all 200ms ease. Naming the property explicitly prevents surprise motion on properties you did not intend to animate, and it avoids forcing the browser to watch and recalculate every animatable property on the element during every state change.

Timing Functions and Easing

A transition's timing function defines the pace of the animation: how the property moves through its range over the duration. The same 300ms transition can feel snappy, sluggish, mechanical, or organic depending entirely on the timing function you choose.

Keyword Values

CSS provides five keyword timing functions that cover the most common needs:

  • ease: Starts slow, accelerates through the middle, then decelerates. The default value. Works well for most hover interactions.
  • ease-in: Starts slow and accelerates to the end. Feels like something leaving the screen; good for exit transitions.
  • ease-out: Starts fast and decelerates to a stop. Feels like something arriving naturally; good for entrance transitions and most UI state changes.
  • ease-in-out: Symmetrical: slow start, fast middle, slow end. Good for back-and-forth motion where both directions matter equally.
  • linear: Constant speed throughout. Feels mechanical and robotic for most motion, but is exactly right for things like progress bars or spinner rotations where constant velocity is the point.

cubic-bezier()

Every keyword timing function is actually a shorthand for a cubic-bezier() curve. A cubic bezier is defined by four numbers: two control point coordinates for the start of the curve and two for the end. Together they describe the shape of the acceleration path. The function signature is cubic-bezier(x1, y1, x2, y2).

Think of the curve as a graph where the horizontal axis is time (0 to 1, start to end of the duration) and the vertical axis is progress through the animation (0 to 1, start value to end value). A straight diagonal line is linear. Pulling the control points away from that diagonal creates curves that speed up, slow down, overshoot, or bounce. You do not need to calculate these by hand: browser DevTools include a visual bezier editor, and tools like cubic-bezier.com let you drag and preview curves in real time.


    /* ease is equivalent to: */
    transition: opacity 300ms cubic-bezier(0.25, 0.1, 0.25, 1);

    /* A custom "spring-like" feel: fast out, gentle overshoot */
    transition: transform 400ms cubic-bezier(0.34, 1.56, 0.64, 1);
When to Use cubic-bezier()

Reach for cubic-bezier() when the keyword values do not quite capture the feel you want. This is especially common for transforms like sliding panels or scaling cards, where a slight overshoot (a y2 value above 1) can make motion feel physical and satisfying. Custom curves are a whole topic on their own, and you will go deeper on this in the Choose Topic options for this unit.

steps()

Unlike bezier curves, steps(n, direction) does not interpolate smoothly. It divides the transition into n discrete jumps, snapping from one position to the next. The direction argument (start or end) controls whether the jump happens at the beginning or end of each interval.

This sounds limiting but is genuinely useful. Steps are the right tool for sprite sheet animations, typewriter text effects, or any motion that is supposed to feel intentionally mechanical or pixelated. If you have a sprite strip of 8 frames, steps(8, end) advances through them cleanly.


    /* 8-frame sprite animation */
    .sprite {
        background-position: 0 0;
        transition: background-position 800ms steps(8, end);
    }

    .sprite:hover {
        background-position: -800px 0;
    }

Transitioning Multiple Properties

When you need to animate more than one property at a time, separate each transition declaration with a comma. Each comma-separated entry has its own property name, duration, timing function, and optional delay.


    .card {
        transition:
            transform 250ms ease-out,
            box-shadow 250ms ease-out,
            opacity 150ms ease;
    }

Writing each property on its own line (as above) is a strong habit: it makes the list readable, easier to edit, and immediately obvious when a property is missing or duplicated.

List Length Mismatch

You can also set the sub-properties separately and use comma-separated lists within each one. When the lists have different lengths, the browser repeats the shorter list to fill the gap. This can be useful as a shorthand, but it is easy to lose track of which value applies to which property once lists grow longer than two or three entries. Explicit comma-separated shorthand declarations (as shown above) are generally easier to reason about.


    /* Sub-property approach: duration list repeats to fill property list */
    .element {
        transition-property: transform, opacity, color;
        transition-duration: 300ms, 150ms;
        /* color gets 300ms (list repeats: 300ms, 150ms, 300ms) */
    }
Caution with Mismatched Lists

Mismatched list lengths are a source of subtle bugs. If you add a property to transition-property and forget to add a corresponding duration, the repeated value may produce unintended timing on properties you did not mean to change. Prefer the explicit shorthand form.

Delays and Sequencing

The transition-delay value tells the browser to wait before starting the animation. A positive delay is a simple pause: the property holds its current value for that duration, then begins transitioning.


    /* Stagger a list of items appearing */
    .nav-item:nth-child(1) { transition: opacity 200ms ease 0ms; }
    .nav-item:nth-child(2) { transition: opacity 200ms ease 50ms; }
    .nav-item:nth-child(3) { transition: opacity 200ms ease 100ms; }
    .nav-item:nth-child(4) { transition: opacity 200ms ease 150ms; }

Negative delay values are less obvious but genuinely useful. A negative delay starts the transition mid-way through: a -100ms delay on a 200ms transition makes it appear to start already halfway complete. This can be used to synchronize transitions that were started at different times, or to make a reversed transition feel snappier on mouse-out.


    /* On hover-out, start the reverse transition already halfway through */
    .button {
        transition: transform 300ms ease-out -150ms;
    }
Forward and Reverse Transitions

A transition defined on the base state applies in both directions: entering and leaving the hover state. You can define different timings for each direction by placing a second transition declaration on the :hover rule, which overrides the base transition only while the hover state is active.

Designing for Reduced Motion

Some users configure their operating system to request reduced motion. This includes people with vestibular disorders (conditions of the inner ear and brain that affect balance and spatial orientation), people prone to motion-induced headaches or nausea, and people who simply find excessive animation distracting. The prefers-reduced-motion media query lets you detect this preference and respond appropriately.

The media query has two values: no-preference (the user has not requested reduced motion) and reduce (the user has). You will almost always write rules inside the reduce branch to scale back or eliminate motion.


    .button {
        transition: transform 300ms cubic-bezier(0.34, 1.56, 0.64, 1);
    }

    @media (prefers-reduced-motion: reduce) {
        .button {
            transition: none;
        }
    }

A common alternative pattern, and often the more maintainable one, is to write your motion rules inside a no-preference query so they only apply when the user has not requested reduced motion. This keeps all motion-related declarations together and avoids having to override them later.


    /* Motion only applies when the user has not opted out */
    @media (prefers-reduced-motion: no-preference) {
        .button {
            transition: transform 300ms cubic-bezier(0.34, 1.56, 0.64, 1);
        }
    }

Both patterns are valid. The reduce override pattern is simpler when motion is the default and you are adding exceptions; the no-preference pattern is cleaner when you are treating reduced motion as the baseline. You will see both in the wild. What matters is that you consciously choose one and apply it consistently in your project.

This Is an Accessibility Requirement

Ignoring prefers-reduced-motion on a site with significant animation is an accessibility failure, not just a polish miss. WCAG 2.1 Success Criterion 2.3.3 (AAA) addresses motion-triggered reactions, and the broader principle of respecting user operating system preferences is part of building for the full range of users. Make reduced-motion support a non-negotiable habit from the start.

Transform Functions

Many of the transitions you write will animate transform. That property does not change layout: the element still occupies its original box in the flow. The dashed ghost in the demo below shows that untransformed footprint. Transforms are for visual offset and motion, not for rearranging document structure. You will go deeper on why transform and opacity are the preferred properties for smooth animation in Keyframes and Reduced Motion.

The most common 2D functions are translate(), rotate(), scale(), and skewX() / skewY(). You can combine them in a single declaration; the browser applies them from right to left. Use the controls below to compare each function. The live box transitions between presets so you can see the interpolation this page is teaching.

Transform Function
Transform Me

transform: none

Seeing It in Action

The demo below shows a card that uses a multi-property transition with a custom easing curve. Use the controls to compare timing functions side by side, and notice how dramatically the perceived quality of the motion changes even when the duration stays constant. The reduced-motion toggle simulates what a user with that OS preference would experience.

Timing Function
CLICK OR FOCUS ME
Card A
CLICK OR FOCUS ME
Card B
CLICK OR FOCUS ME
Card C

Check Your Understanding

Put your new skills to the test with this coding challenge. Write the CSS to produce the described transition behavior, then use the copy icon to copy your completed code and paste it as a prompt to your AI assistant for feedback.


        /*
         * A .nav-link element needs the following behavior:
         *
         * 1. On hover, smoothly transition its color and its
         *    bottom border (use border-bottom-color) over 200ms,
         *    using ease-out. The border should start its
         *    transition 50ms after the color begins.
         *
         * 2. Write a prefers-reduced-motion block that removes
         *    all transition motion for users who prefer it.
         *
         * Write only the CSS. No HTML needed.
         */

    

Resources