Transitions, Transforms, and Respecting Motion

What this is. A transition smooths a change that was going to happen anyway. You declare it on the resting state, not on the hover state, so it applies in both directions.

`

.button {

background: var(--brand);

transition: background 200ms ease, transform 200ms ease;

}

.button:hover { transform: translateY(-2px); }

`

Transform, not position. transform: translateY(-2px) moves an element visually without affecting layout, so nothing around it shifts. Animating top or margin forces the browser to recalculate the layout of the page on every frame, which is what makes some sites feel sluggish. transform and opacity are the two cheapest things to animate.

✦ prefers-reduced-motion is not optional

For people with vestibular disorders, motion on a screen can cause genuine nausea and dizziness. The operating system already has a setting for this, and honoring it is three lines of CSS. Motion should be an enhancement that can be switched off, never something the interface depends on to make sense.

LIVE PREVIEW
loading editor…

Your turn → Move the transition declaration from .btn into .btn:hover. The lift now animates on the way in but snaps back instantly on the way out, because there is no transition on the resting state to return to.

◈ Graded Build

Set up the design tokens for your portfolio. Define three custom properties on :root named brand, ink and surface, then build a button class that uses var() for its background and color, and transitions its background over 200ms.

Checked against the page you actually render, not against how you wrote it. 4 visible and 2 hidden checks.

loading editor…

Mark this lesson complete

Signed in, your progress follows you to every device.

Next: Practice Test →
← Back