CSS Fade Keyframes Generator
Generate configurable CSS @keyframes fade in and fade out animations, with custom duration and easing. Copy the ready CSS for your transitions.
CSS
—
CSS @keyframes fade: animate opacity the right way
A fade is the simplest CSS animation: opacity goes from 0 to 1 (fade in) or 1 to 0 (fade out) over a duration. Behind the scenes you declare a @keyframes rule, then bind it to an element via the animation shorthand. Opacity (alongside transform) is one of only two properties the browser can animate purely on the compositor — meaning it skips layout and paint, runs on the GPU, and stays smooth even on low-end devices.
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
.element {
animation: fadeIn 0.5s ease forwards;
}
Animation shorthand decoded
The full shorthand is animation: name duration timing-function delay iteration-count direction fill-mode play-state. The two values that trip people up are fill-mode and timing-function:
- fill-mode —
forwardskeeps the end state after the animation finishes (essential for fade-in),backwardsapplies the start state during the delay,bothdoes both, default isnone(reverts to original CSS — usually what beginners don't want). - timing-function —
easeis the default but feels lazy;ease-outis usually best for fades (starts fast, ends slow).cubic-bezier(0.4, 0, 0.2, 1)is the "standard" Material curve. - iteration-count —
infinitefor pulsing, combined withdirection: alternatefor breathing.
Variations: fade-in-up, crossfade, stagger
Adding transform: translateY(20px) in from creates fadeInUp; translateX gives left/right variants. Crossfade animates two stacked elements simultaneously — one fading out, one fading in. Stagger applies the same animation to a list of children with incrementing animation-delay, producing a cascading reveal. Daniel Eden's Animate.css library ships hundreds of ready-made fade keyframes if you don't want to write your own.
Performance and accessibility
Stick to opacity and transform — both are GPU-composited. Animating width, height, top or left triggers layout on every frame and tanks performance. Hint the browser with will-change: opacity, but remove it after the animation finishes (it consumes GPU memory). Most importantly, respect @media (prefers-reduced-motion: reduce) — users with vestibular disorders set this OS-level flag and your CSS should disable or shorten the animation accordingly.
@media (prefers-reduced-motion: no-preference) {
.element { animation: fadeIn 0.5s ease forwards; }
}
Modern alternatives: WAAPI and View Transitions
The Web Animations API (WAAPI) is the JavaScript equivalent — element.animate([{opacity:0},{opacity:1}], 500) — useful when you need precise control or to trigger animations from logic. The View Transitions API (Chrome 111+, 2023) animates between two DOM states (or two pages) with a single line, replacing dozens of manual keyframes for typical page transitions. For scroll-triggered fades, pair IntersectionObserver with a CSS class toggle so animations run only when the element enters the viewport.
FAQ
Is CSS animation faster than JavaScript? For opacity and transform, yes — they run on the compositor. JS-based libraries like GSAP are competitive when you animate properties that aren't composited or need synchronisation across many elements.
Can I animate SVG paths? Not via CSS @keyframes alone for the d attribute. Use SMIL, GSAP's MorphSVGPlugin or Snap.svg. SVG opacity, transform and stroke properties animate fine with CSS.
How do I loop forever? Add animation-iteration-count: infinite. Combine with animation-direction: alternate for a back-and-forth pulse.
Why is my element invisible after the animation? The default fill-mode is none, which reverts to the pre-animation CSS (opacity 1, or whatever you set). Add forwards to keep the end state.
Related Tools
Accessible CSS Focus Ring Generator
Generate an accessible CSS focus ring with good contrast following the WCAG guidelines. Improve keyboard navigation on your site and copy the code.
SVG Pattern Generator
Create repeatable SVG patterns for website backgrounds: dots, lines, checkerboard, grid, diagonal and hexagons. Customize colors and size. Copy the SVG code or CSS background-image.
CSS clamp() Fluid Typography
Generate fluid typography with CSS clamp() from a minimum size, maximum size and viewport range. Fonts scale smoothly across screens, no media queries.
CSS Glow Effect Generator
Generate CSS glow/neon effect with layered box-shadow / text-shadow.
Animated CSS SVG Blob Generator
Generate an SVG blob with CSS morphing animation, ready to paste into landing pages and website sections. Create organic, dynamic backgrounds and copy the code.
CSS clip-path Shape Generator
Generate CSS clip-path for common shapes: triangle, diamond, hexagon, star, arrow, circle, speech.