/* slides 50px to the right */ .moveBox { transition: transform .6s ease; } .card:hover .moveBox { transform: translateX(50px); }
/* spins around its centre */ .spinBox { transition: transform .6s ease; } .card:hover .spinBox { transform: rotate(45deg); }
/* grows the box to 140% */ .growBox { transition: transform .6s ease; } .card:hover .growBox { transform: scale(1.4); }
/* tilts the box sideways */ .tiltBox { transition: transform .6s ease; } .card:hover .tiltBox { transform: skew(20deg); }
@keyframes move {
from {
transform: translateX(-70px);
}
to {
transform: translateX(70px);
}
}
.ball {
animation-name: move;
animation-duration: 2s;
animation-iteration-count: infinite;
}
.ball {
animation-name: move;
animation-duration: 2s;
animation-delay: 1s;
animation-iteration-count: infinite;
}
/* runs 3 times, then stops */ .ball { animation-name: move; animation-duration: 1s; animation-iteration-count: 3; }
/* forwards, then backwards */ .ball { animation-name: move; animation-duration: 2s; animation-iteration-count: infinite; animation-direction: alternate; }
/* keeps the last frame's style */ .ball { animation-name: move; animation-duration: 2s; animation-fill-mode: forwards; }
/* hover the ball to pause it */ .ball { animation-name: move; animation-duration: 2s; animation-iteration-count: infinite; } .ball:hover { animation-play-state: paused; }
/* slow, fast, then slow */ .ball { animation-name: move; animation-duration: 2s; animation-timing-function: ease; animation-iteration-count: infinite; }
/* pulls back, then overshoots */ .ball { animation-name: move; animation-duration: 2s; animation-timing-function: cubic-bezier(.68, -.55, .27, 1.55); animation-iteration-count: infinite; }
/* jumps in 5 steps, no gliding */ .ball { animation-name: move; animation-duration: 2s; animation-timing-function: steps(5); animation-iteration-count: infinite; }
CSS transitions and animations are mostly used to improve UX, provide instant visual feedback, and make interfaces feel alive without heavy JavaScript.
Buttons, cards, links
Skeleton screens, loading icons (reduces perceived wait time)
Pulsing notification badges, bouncing scroll arrows
Smooth fade-ins for modals, menus
While CSS handles simple state changes cleanly, JavaScript—using the Web Animations API or GSAP (GreenSock, an industry-standard JS animation library)—is better suited for complex, interactive motion.
Animations synced to scroll progress, drag gestures, or game logic
Multi-step choreographies or natural spring mechanics
When you need to scrub a timeline, reverse dynamically, or interrupt an animation based on logic
Standard UI buttons, dropdowns, simple hover states
Complex scroll-triggered product storytelling (e.g., Apple)
Animating layout properties like width, height, top, left, or margin forces the CPU to recalculate layout and repaint pixels on every frame, causing lag. In contrast, transform and opacity run directly on the GPU, keeping animations smooth at 60fps.
When someone turns on "Reduce motion" in their OS settings, the browser lets your CSS know, but nothing changes on its own.
You decide what happens inside a @media (prefers-reduced-motion: reduce) block: switch heavy movement off, or swap it for something calmer, like a fade.
Hover this card to see a calmer version below.