Snippets

CSS Micro-animations

A curated set of small, reusable CSS keyframe animations. Every card renders the effect live on an infinite loop, so what you see is exactly what the snippet produces. Copy the self-contained @keyframes block and class straight into your stylesheet.

How keyframe animation works

Each snippet follows the same two-part structure. A @keyframes rule declares the animation states, and a utility class such as .anim-pulse applies them with the animation shorthand. Inside the rule, the from and to keywords mark the first and last frames, while percentage blocks such as 50% define intermediate stops. During playback the browser interpolates the property values between the declared frames, so you describe two or more states and the engine produces every frame in between. Percentage stops act as checkpoints inside each cycle, and the easing function shapes the movement between them. Duration, timing function and loop count all live in the class, so the same keyframes can feed several utilities.

Every card below runs live before you copy it.

Fade In

Ease an element from fully transparent to fully opaque: the go-to entrance for text and cards.

Loop

CSS

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.anim-fade-in {
  animation: fade-in 1.6s ease-in-out infinite;
}

Slide Up

Rise into place from below while fading in: a classic reveal for sections and modals.

Loop

CSS

@keyframes slide-up {
  from {
    transform: translateY(24px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.anim-slide-up {
  animation: slide-up 1.6s ease-out infinite;
}

Scale In

Grow from 60% with a fade for a gentle pop-in on dialogs, tooltips, and cards.

Loop

CSS

@keyframes scale-in {
  from {
    transform: scale(0.6);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.anim-scale-in {
  animation: scale-in 1.6s ease-out infinite;
}

Pulse

A subtle breathing scale that draws the eye to CTAs, badges, and live indicators.

Loop

CSS

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.14);
    opacity: 0.82;
  }
}

.anim-pulse {
  animation: pulse 1.5s ease-in-out infinite;
}

Spin

Constant 360° rotation for loaders, spinners, and processing states.

Loop

CSS

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.anim-spin {
  animation: spin 1.1s linear infinite;
}

Bounce

A playful vertical hop with easing that lands softly at the bottom.

Loop

CSS

@keyframes bounce {
  0%,
  100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-30px);
  }
  60% {
    transform: translateY(-12px);
  }
  80% {
    transform: translateY(-4px);
  }
}

.anim-bounce {
  animation: bounce 1.4s ease-in-out infinite;
}

Shake

Rapid horizontal jitter for error states, invalid input, and attention-grabbing alerts.

Loop

CSS

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-8px);
  }
  40% {
    transform: translateX(8px);
  }
  60% {
    transform: translateX(-6px);
  }
  80% {
    transform: translateX(6px);
  }
}

.anim-shake {
  animation: shake 0.7s ease-in-out infinite;
}

Shimmer

A light sweep glides across a surface: the classic skeleton-loader treatment.

Loop

CSS

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.anim-shimmer {
  background: linear-gradient(
    110deg,
    #26262b 40%,
    #a35fff 50%,
    #26262b 60%
);
  background-size: 200% 100%;
  animation: shimmer 2.2s linear infinite;
}

Wobble

Rock side to side with a slight rotation for playful, offbeat emphasis.

Loop

CSS

@keyframes wobble {
  0%,
  100% {
    transform: rotate(0deg);
  }
  25% {
    transform: rotate(-12deg);
  }
  75% {
    transform: rotate(12deg);
  }
}

.anim-wobble {
  animation: wobble 1s ease-in-out infinite;
}

Flip

Full 3D rotation around the Y axis for card reveals and coin-flip effects.

Loop

CSS

@keyframes flip {
  from {
    transform: perspective(400px) rotateY(0deg);
  }
  to {
    transform: perspective(400px) rotateY(360deg);
  }
}

.anim-flip {
  animation: flip 1.8s ease-in-out infinite;
}

Breaking down the animation shorthand

The animation property groups several sub-properties into one declaration, and that order is what keeps these snippets compact. The first word is the keyframe name, the time value is the duration, the keyword is the easing function, and the trailing infinite sets the iteration count. Because the shorthand lives inside the class, a single keyframes rule can feed many variations. Fade-in is reused whenever text or a card should enter quietly, while slide-up adds a translateY offset to the same opacity fade for a directional reveal.

Easing picks the curve that fits each preset's role.

When to use animation instead of transition

Transitions and animations solve different problems, and choosing between them keeps stylesheets predictable. A transition reacts to a state change such as a hover or a class toggle, and it runs once. An animation plays on its own schedule, which makes it the right tool for entrances, attention states and loops that should run without any user interaction. The distinction matters because the two features use separate longhand properties, and mixing them on the same property can produce surprising results.

Accessibility and reduced motion

Motion is not neutral for every visitor. WCAG 2.2 criterion 2.3.3 covers animation triggered by interaction, and the broader guidance for motion-sensitive users recommends that large, flashing or long-running movement offer a way to pause, stop or hide it. The infinite loops in this library are decorative previews, but the same snippets can feel strong in a real interface. Plan a companion rule that respects the prefers-reduced-motion media query and replaces looping motion with a static state when the visitor asks for less movement. It costs little and prevents the worst outcomes for sensitive users.

Common mistakes

The most frequent errors appear in the shorthand, not in the keyframes. Because animation resets any sub-property you omit, declaring it twice on the same element can silently drop an earlier easing or delay, so keep one source of truth per class. Second, compare the intended role with the effect. A shake that fits a compact error message can feel aggressive on a large banner. Third, remember the iteration count, because a long-running infinite loop on a busy page deserves the accessible treatment described above.

One sentence per class. Name, duration, easing, repetition.

Browser support

The animation shorthand and the @keyframes rule are supported across current engines per the MDN compatibility data.

The keyframe animation references behind this library

MDN Using CSS animations
Explains the @keyframes rule, the animation shorthand and its sub-properties, which is the exact structure every snippet on this page follows.
MDN transition
Documents the transition property, the basis for the note on choosing between transitions for interaction feedback and animations for scheduled motion.
MDN gradient
Defines the linear-gradient() function that the shimmer card animates, including how color stops and background positioning interact.
WCAG 2.2
Sets the animation and motion criteria, including success criterion 2.3.3, behind the reduced-motion guidance in the accessibility section.
WCAG 2.2 quick reference
A filterable view of the success criteria used to check whether an animation can pause, stop or hide for users who request less motion.