CSS Animation Cheatsheet: Interactive Visual Guide
October 15, 2026 | Cheatsheet | CSS
By Syed · Frontend Engineer & Creator of UITweak
Animation has a lot of small properties that are easy to mix up. Every section below has a live demo: change the value, watch what happens, copy the code.
The animation shorthand
The shorthand sets all seven animation sub-properties in one declaration, and any value you leave out resets to its initial value instead of keeping a previous setting. That means a second animation shorthand later in the cascade will silently wipe an animation-delay or animation-fill-mode set with longhands above it. When a shorthand seems to break one property, check whether another shorthand below it reset the rest.
.box {
animation: slide-in 0.6s ease-out 0.2s 1 normal both;
}
@keyframes slide-in {
from { opacity: 0; transform: translateX(-24px); }
to { opacity: 1; transform: translateX(0); }
}animation-timing-function
Each timing function maps elapsed time to progress between two keyframes, and the browser evaluates that curve on every frame to pick the in-between value. ease-out moves fast at the start and settles gently, which suits entrances, while ease-in accelerates and suits exits. The curve applies between every pair of keyframes, so a four-keyframe animation repeats the same easing three times.
animation-timing-function: ease-out;
.box {
animation: slide 1.6s ease-out;
}
/* Tailwind: ease-linear, ease-in, ease-out, ease-in-out,
or arbitrary: ease-[cubic-bezier(0.68,-0.55,0.27,1.55)] */animation-direction
Direction decides the playback order of the keyframes on each iteration: normal always runs from the first keyframe to the last, while reverse starts at the last and plays backward. alternate ping-pongs, playing forward on odd iterations and backward on even ones, which gives you a loop without writing mirrored keyframes. The timing function mirrors with the direction, so an ease-out entrance still decelerates on the return trip.
.box {
animation: slide 1.8s ease-in-out infinite;
animation-direction: alternate;
}animation-fill-mode
By default an element shows its ordinary styles during any delay and snaps back to them the moment the animation finishes. backwards applies the first keyframe during the delay so the element never flashes its end state while waiting, forwards holds the last keyframe after the final iteration, and both covers both ends. It only applies while the animation is attached; removing the class returns the element to its base styles.
The box waits 1s, then fades up once. Watch what it looks like before and after with each fill mode:
.box {
animation: fade-up 0.8s ease-out 1s 1 both;
}
/* none: jumps back after finishing.
forwards: keeps the last keyframe.
backwards: applies the first keyframe during the delay.
both: backwards + forwards. The safest default. */animation-iteration-count
The count can be fractional: 2.5 ends the animation halfway through the third pass, freezing mid-keyframe unless a fill mode holds an endpoint. infinite loops forever, which also means forwards has no final state to hold and is effectively ignored. Duration times count is the active running time; add any delay when timing an animationend handler.
.box {
animation: pulse 1s ease-in-out infinite;
}
/* Tailwind: animate-pulse, animate-spin, animate-ping, animate-bounce */animation-delay
A positive delay pauses before the first keyframe; without a fill mode the element sits in its base styles for the whole wait, flashing its finished state. A negative delay fast-forwards instead, so the first painted frame is already partway through, the standard trick for staggered loaders. The delay runs once, before the first iteration; it never repeats between iterations.
.box {
animation: pop 0.5s ease-out 0.0s both;
}
/* Tip: stagger lists with calc():
animation-delay: calc(var(--i) * 80ms); */prefers-reduced-motion
This media query does not animate anything itself; it only gives you a branch to tone motion down for people who ask for less of it. The common pattern sets animation and transition durations to a millisecond rather than removing the animation outright, which keeps animationend listeners working for any JavaScript that depends on them. Reserve the override for decorative motion; keep fades that carry meaning, like a state change that would otherwise be invisible.
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after {
animation-duration: 0.01ms !important;
transition-duration: 0.01ms !important;
}
}Want 280+ ready-made presets? Try our free CSS Animation Generator with live preview and one-click code export.
Common Production Bugs & Fixes
The entrance plays, then the element snaps back
You run a one-shot slide-in, the animation looks perfect, and on the last frame the element jumps back to its starting position. The default fill mode is none, so once the final iteration ends the browser drops every animated value and the element's ordinary styles take over again. Set the fill mode to forwards, or both with a delay, so the last keyframe keeps applying after the animation finishes.
.toast {
animation: slide-in 0.45s ease-out both;
}
@keyframes slide-in {
from { opacity: 0; transform: translateY(12px); }
to { opacity: 1; transform: translateY(0); }
}Two animations target the same property and one silently wins
You add a second animation that also animates transform, and the first motion disappears: the element spins but never floats, or vice versa. When several animations target the same property, the last one listed wins on every frame, and keyframes never merge across animations. Combine both motions into one @keyframes block, or use animation-composition: accumulate where values must add up instead of replacing each other.
/* two transforms cannot stack across animations, so merge them */
@keyframes float-spin {
from { transform: translateY(0) rotate(0deg); }
to { transform: translateY(-10px) rotate(360deg); }
}
.badge { animation: float-spin 3s ease-in-out infinite; }Animating width, height, or top stutters on phones
Expanding a panel by animating height, or sliding a drawer with left, feels choppy on low-end devices. Those properties force the browser through layout and paint on every frame, recalculating geometry for the element and its neighbors before anything can be drawn. transform and opacity skip both steps in the common case and run on the compositor thread, so prefer translate for movement and scale for resizing.
.drawer {
transform: translateX(-100%);
transition: transform 0.32s ease-out;
}
.drawer.open { transform: translateX(0); }Reduced-motion users still get the full animation
Your loader or ambient loop keeps running at full intensity even for users who asked their OS for reduced motion. The prefers-reduced-motion media query is opt-in: nothing in CSS disables motion automatically, so every animation you ship stays on unless you add the override. Add one global rule that collapses animation and transition durations, and make decorative loops degrade to a static frame.
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after {
animation-duration: 0.01ms !important;
transition-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
}
}Real-World Recipes
Staggered card entrance
Give each card the same entrance animation but a growing animation-delay, and set the fill mode to backwards so every card holds its hidden first keyframe during the wait instead of flashing visible. The from keyframe carries opacity: 0, so before the animation is attached at all the cards render normally and the page never shows a broken state. Keep the total stagger under about half a second so the page never feels slow to arrive.
.card {
animation: rise 0.5s ease-out backwards;
}
.card:nth-child(2) { animation-delay: 0.08s; }
.card:nth-child(3) { animation-delay: 0.16s; }
.card:nth-child(4) { animation-delay: 0.24s; }
@keyframes rise {
from { opacity: 0; transform: translateY(16px); }
to { opacity: 1; transform: translateY(0); }
}Indeterminate loading spinner
Build the spinner from a bordered circle with one side colored and the rest transparent, then rotate it with a linear infinite animation. linear matters here: any easing would make the rotation visibly pulse once per revolution. Size it in em so it scales with surrounding text, and add the reduced-motion override so it degrades to a static ring.
.spinner {
width: 1.5em; height: 1.5em;
border-radius: 50%;
border: 0.2em solid rgba(0, 0, 0, 0.15);
border-top-color: currentColor;
animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
.spinner { animation: none; }
}Attention pulse for a notification dot
Scale the dot up and back with an ease-in-out infinite loop, keeping the motion on transform so it stays on the compositor thread. Keep the amplitude small, around ten percent, so the pulse reads as a nudge rather than an alarm. Because the pulse loops forever, pair it with a reduced-motion rule that leaves a static dot.
.dot {
width: 10px; height: 10px; border-radius: 50%;
background: #ef4444;
animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
0%, 100% { transform: scale(1); }
50% { transform: scale(1.25); }
}
@media (prefers-reduced-motion: reduce) {
.dot { animation: none; }
}FAQ
What is the practical difference between a transition and an animation?
A transition only runs when a property value changes, so it needs a trigger like a hover or a toggled class, and it always travels directly from the old value to the new one. An animation runs from its keyframes on its own schedule, needs no trigger, can pass through intermediate stops, and can loop. Use transitions for state changes, animations for repeating or multi-step motion.
Can keyframes animate to height: auto?
No. Interpolation needs two concrete numbers, and auto is not one, so the browser cannot compute the in-between frames and the animation jumps. The established workaround animates grid-template-rows between 0fr and 1fr on a wrapper with an overflow-hidden child, giving a smooth expand and collapse without guessing a pixel height.
Can I trust animationend to fire exactly when the motion stops?
Not for anything critical. Background tabs, dropped frames, and a reduced-motion override can delay, compress, or cancel the animation, and with several animations on one element each fires its own event. Treat animationend as a hint for cosmetic follow-ups; keep essential logic on timers or state changes instead.
Does a paused animation still respond to clicks?
Yes. animation-play-state: paused freezes the rendered frame but changes nothing about hit-testing or the event model; the element keeps its place in layout and stays fully interactive. To also block clicks, add pointer-events: none separately.
More cheatsheets: