Animating State Changes with Transitions

suggest change

A transition interpolates an animatable property when its computed value changes:

.card {
  background-color: white;
  transform: translateY(0);
  transition:
    background-color 200ms ease,
    transform 200ms ease;
}

.card:is(:hover, :focus-within) {
  background-color: hsl(210 40% 96%);
  transform: translateY(-0.25rem);
}

Prefer explicit property names over transition: all; this documents the intended effect and avoids animating unrelated changes. Not every property is animatable, and transitions to or from intrinsic keywords such as auto are not universally interpolated.

Do not make essential content depend on hover, which may be unavailable on touch or keyboard-driven interfaces. The example also responds when a descendant receives keyboard focus.

Respect the user's motion preference:

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

Transitions, like animations, no longer require vendor prefixes in modern browsers.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents