Skip to article content
FrontendXLesson 29 / 30

Transitions, animations and reduced motion

Build semantic, accessible and responsive interfaces from a blank page, and explain why each layout and styling decision works.

advanced · about 40 minutes · 2 exercises

  • Implement
  • Debug

What you will be able to do

#
  • Animate properties that are cheap to animate and avoid layout thrash.
  • Respect prefers-reduced-motion without removing all feedback.

Overview

#

A transition animates a property when its value changes, usually on a state such as :hover or :focus. An animation runs a keyframe timeline independently. Both should target properties the compositor can handle cheaply: transform and opacity. Animating width, height, top or margin forces layout on every frame and causes jank.

snippet.css
.card {
  transition: transform 150ms ease, opacity 150ms ease;
}
.card:hover {
  transform: translateY(-2px);
}

@keyframes pulse {
  from { opacity: 1; }
  to { opacity: 0.6; }
}
.badge {
  animation: pulse 1.5s ease-in-out infinite alternate;
}

Give interactive elements a visible focus state, and use transitions to reinforce state changes rather than to decorate. Keep durations short, roughly 100 to 300ms for UI feedback. Long animations feel sluggish and delay the user.

Some users have motion sensitivity. prefers-reduced-motion lets you reduce or remove non-essential motion. Do not remove all feedback; instead, replace large movement with a subtle change such as a color or opacity shift, and keep essential state changes visible.

snippet.css
@media (prefers-reduced-motion: reduce) {
  .card { transition: none; }
  .badge { animation: none; }
  .card:hover { transform: none; opacity: 0.9; }
}

Respect prefers-reduced-motion for parallax, auto-playing carousels and large entrance animations especially. Motion that carries meaning, such as a progress indicator, should still communicate progress through a non-motion cue when motion is reduced.

Exercises

#

Reference answers and expected output are authored, not executed in this browser. Nothing you type is run, and there is no Run or Pass control on this page.

  1. Exercise 1Implement

    Add a hover lift to a card using a compositor-friendly property, and disable the motion when the user prefers reduced motion while keeping a visible change.

    starter.css
    .card { /* add transition and hover */ }

    Reveal the reference answer
    reference.css
    .card {
      transition: transform 150ms ease;
    }
    .card:hover {
      transform: translateY(-2px);
    }
    @media (prefers-reduced-motion: reduce) {
      .card { transition: none; }
      .card:hover { transform: none; outline: 2px solid currentColor; }
    }

    Authored expected output: The card lifts on hover using transform, and reduced-motion users get a non-motion state change instead.

    transform is composited cheaply, and the reduced-motion query swaps movement for an outline.

  2. Exercise 2Debug

    This animation causes visible jank because it animates a layout property. Rewrite it to animate a compositor-friendly property.

    starter.css
    .panel { animation: slide 300ms ease; }
    @keyframes slide { from { left: -100%; } to { left: 0; } }

    Reveal the reference answer
    reference.css
    .panel { animation: slide 300ms ease; }
    @keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(0); } }

    Authored expected output: The animation moves the panel with transform instead of left.

    transform does not trigger layout, so the animation runs on the compositor.

Common misconceptions

#
  • Animating width and height is fine because modern machines are fast.
  • prefers-reduced-motion means removing all visual feedback.

Follow-up practice

#
  • html-css-30-modern-css

Related resources

#

Your progress

#

Answers, drafts and completion marks are stored only in this browser. Nothing is sent to a server and no account is used.

Verification: authored. Answers and outputs on this page are authored reference material, not executed results.

© 2026 FrontendX. All rights reserved.