MotionLift

Animated backgrounds for websites: CSS, canvas or video

By Pulse Labs · Published · Updated · 2 min read

The cheapest good animated background is a CSS layer behind your content: two or three soft gradients that drift slowly, drawn with transform so the browser can run them off the main thread, and switched off when the visitor asks for less motion. Canvas and video can look richer, but they cost more to load and run. Pick the simplest one that gets the effect you want.

Below is a background you can paste, then a comparison of the three approaches, and the rule that matters most: keep moving light away from your text.

A CSS background you can paste

Live demo Drifting light behind content
Markup · html
<div class="bg" aria-hidden="true"><i></i><i></i></div>
<main>
  <h1>Saltmarsh Kitchen</h1>
  <p>Seasonal plates, cooked over fire.</p>
</main>
Styles · css
.bg { position: fixed; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; }
.bg i { position: absolute; width: 70vmax; height: 70vmax; border-radius: 50%; filter: blur(40px); opacity: .55; }
.bg i:nth-child(1) { left: -20vmax; top: -30vmax; background: radial-gradient(closest-side, #7a63f0, transparent); }
.bg i:nth-child(2) { right: -25vmax; bottom: -35vmax; background: radial-gradient(closest-side, #e0702a, transparent); }
main { position: relative; z-index: 1; padding-top: 24px; }
@keyframes a { to { transform: translate3d(14vmax, 10vmax, 0); } }
@keyframes b { to { transform: translate3d(-12vmax, -9vmax, 0); } }
@media (prefers-reduced-motion: no-preference) {
  .bg i:nth-child(1) { animation: a 14s ease-in-out infinite alternate; }
  .bg i:nth-child(2) { animation: b 18s ease-in-out infinite alternate; }
}

The layer is aria-hidden, ignores the pointer, and sits behind the content. Under reduced motion the animation stops and the gradients stay as a still backdrop, which still looks designed. The blur is applied once to a layer that is then moved, which is cheaper than animating the blur itself; web.dev's animation guide lists blur and shadows among the effects that take longer to paint.

CSS, canvas or video

ApproachLooks likeCostPick it when
CSS gradients or shapesSoft drifting light, simple shapesSmall. No script, no downloadYou want atmosphere and have a few minutes
Canvas or WebGLParticles, networks, fluids, 3DA script that draws every frame, so it runs continuously and uses the device's processor or graphics hardwareThe motion is the point, and you can add a still fallback and stop it when it is off screen
Looping videoAnything a designer can film or renderA file download, and it plays whether or not anyone is lookingYou need exactly that footage; keep the file short, and offer a still image for reduced motion

Keep moving light away from text

Text laid over a moving background changes contrast as the light passes under it, which is tiring to read. Two fixes. Put the content on a solid or lightly tinted panel, or draw the animation only in the empty parts of the page. MotionLift takes the second route: it chooses a backdrop from what the page is about, in the page's own colours, and draws it only in empty space, keeping text, pictures, cards and forms clear. The backdrops are Skyline of bars, Network, Map contours, Currents, Embers, Lens light and Glass shards, or you can let it choose.

The restaurant example uses Embers rising in the empty space of a made-up kitchen's page. MotionLift also stops the drawing first on a device that cannot keep up. For the costs of every background see animation and page speed.

Checklist

  • Behind the content, aria-hidden, pointer events off.
  • Moved with transform or opacity.
  • Still version for reduced motion.
  • Contrast of text checked against the lightest part of the backdrop.
  • Stops or pauses when it is not visible, if it is canvas or video.