You do not need JavaScript to make a page feel alive. Two CSS features — transforms and transitions — handle most of the motion you see on the modern web: buttons that lift on hover, cards that zoom slightly, menus that slide in. They are simple, they run smoothly, and they are the right first step into animation.
A transform changes an element's shape or position without disturbing the layout around it. You can move it, scale it, rotate it, or skew it — and because transforms do not trigger a page reflow, they are fast.
.card {
transition: transform 0.25s ease, box-shadow 0.25s ease;
}
.card:hover {
transform: translateY(-4px) scale(1.02);
box-shadow: 0 12px 24px rgba(0, 0, 0, 0.15);
}
A transition tells the browser how to move between two states. Without one, a hover change snaps instantly. With one, the same change glides. You list the properties to animate, how long the animation takes, and the easing curve that controls its feel.
button {
background: #10b981;
transition: background 0.2s ease, transform 0.15s ease;
}
button:hover {
background: #059669;
transform: scale(1.05);
}
button:active {
transform: scale(0.97);
}
A few practical rules. Animate transform and opacity whenever you can — they are the cheapest properties for the browser. Avoid transitioning layout properties like width, height, margin, or top, because they force the browser to recalculate the whole page on every frame. And keep durations short: 150–300ms feels responsive, while anything over half a second starts to feel slow.
Transforms and transitions will not replace JavaScript animation for complex sequences. But for hover effects, toggles, and small moments of feedback, they are all you need — and your users will feel the difference immediately.
Top comments (0)