Transitions and Transformations
Create smooth UI interactions using transitions, transforms, timing functions, and compositing-friendly animation properties.
CSS Transitions
Transitions interpolate property changes over time. A transition typically specifies the property, duration, timing function, and optional delay.
Transitions work when a property has a different computed value before and after a state change.
.button {
background: #2563eb;
transition:
background-color 180ms ease,
transform 180ms ease;
}
.button:hover {
background: #1d4ed8;
transform: translateY(-2px);
}- Transitions smooth state changes.
- Transition only the properties that need animation.
What does a CSS transition primarily do?
Transform
The transform property can translate, scale, rotate, or skew an element without changing normal document flow in the same way as layout properties. Transform functions can be composed.
Transforms are commonly used for visual movement because they can often be handled efficiently by browser rendering pipelines.
.card:hover {
transform: translateY(-6px) scale(1.01);
}
.icon {
transform: rotate(45deg);
}- Transforms visually modify an element without normal-flow repositioning.
- Translate and scale are common interaction effects.
Which property is commonly used for visual movement without changing normal layout geometry?
Timing Functions
Timing functions control the rate at which an animation progresses. Common keywords include linear, ease, ease-in, ease-out, and ease-in-out. Custom cubic Bézier curves can provide more precise motion.
Good motion usually has a purpose: communicating state, hierarchy, or spatial relationships.
.panel {
transition: transform 300ms cubic-bezier(0.22, 1, 0.36, 1);
}- Timing functions control animation pacing.
- Use motion to communicate interaction rather than decoration alone.
What does a timing function control?