Transforms, Transitions, and Animation
Add purposeful motion with interpolable properties, stable layout, reduced-motion alternatives, and explicit state changes.
Transforms change an element's rendered coordinate space without reflowing surrounding boxes. Transitions animate changes between property values, while keyframe animations can define multiple stages. Motion should clarify state and hierarchy, avoid surprise, and respect user preferences.
See the core pattern
Read this rule set from the outside in. Identify the inputs, the decision or transformation, and the result before changing it.
.card { transition: translate 160ms ease, border-color 160ms ease; } .card:hover { translate: 0 -.2rem; } @media (prefers-reduced-motion: reduce) { .card { transition: none; } .card:hover { translate: none; } }Working rules
- Animate named properties rather than all
- Keep focus and state visible without motion
- Provide a reduced-motion behavior that preserves information
A common mistake
transition: all can animate an unintended layout or color change after future maintenance.
Guided practice
Add a small card emphasis that does not move content around it and disappears under reduced motion.
- Copy the example into the editable notebook below.
- Change one thing at a time and keep the program or rule valid.