CSS animation

CSS playing a named keyframe sequence on its own: no state change needed, and it can loop, reverse, or pause.

@keyframes animationlooping animation in CSScss animation that plays by itselfinfinite loop animation cssanimate without hoverkeyframe animationcss anmiationmake it pulse forever

See it

Live demo coming soon

What it is

Where a transition waits for something to change, an animation just runs. You write the choreography once in a '@keyframes' block and attach it: 'animation: pulse 1.2s ease-in-out infinite'. That shorthand is packing eight properties (name, duration, timing function, delay, iteration count, direction, fill mode, play state), which is why it looks cryptic.

Use it for anything self-starting or repeating: spinners, skeleton shimmer, marquees, attention pulses, on-load entrances, drifting background shapes. Use it too when the motion has middle waypoints, since a transition only knows start and end.

Gotchas: reach for 'animation-fill-mode: forwards' only when the final keyframe genuinely has to persist, since without it the element snaps back to its pre-animation styles the instant it finishes. Even then the sturdier fix is to make the element's underlying styles match that last pose, so nothing depends on the animation staying attached. On an infinite animation the property does nothing at all, because the animation never finishes. Infinite animations also keep the compositor awake, so stick to transform and opacity and pause them off-screen. And re-triggering the same animation on the same element does nothing: you have to remove the class, force a reflow, and re-add it, or drop to the Web Animations API instead.

Ask AI for it

Build this with a CSS @keyframes animation rather than a transition, because it has to run on its own with no trigger. Make it a self-running pulse: at 0% and 100% use transform: scale(0.98) with opacity 0.7, and at 50% use transform: scale(1) with opacity 1. Animate transform and opacity only. Attach it with the longhand properties so the intent reads clearly: animation-name, animation-duration: 1.4s, animation-timing-function: ease-in-out, animation-iteration-count: infinite. Leave animation-fill-mode off, since an infinite animation never finishes and has nothing to fill forward to. Set 'animation-play-state: paused' when the element is off-screen and when 'prefers-reduced-motion: reduce' matches.

You might have meant

keyframescss transitioniteration countfill modeanimation direction

Go deeper