Skip to content

Animated Gradient Background

Pure CSS hero section with a slowly shifting multi-color gradient, drifting blurred blobs and a grain overlay, customizable through CSS variables.

Also known as: animated gradient hero, moving gradient background, gradient hero section, blurred blob background

Animated Gradient Background live demo

Open in new tab

Pure CSS code (HTML, CSS)

An animated gradient background in pure CSS: a hero section whose coral, pink, violet and teal gradient drifts slowly, with blurred color blobs and a fine grain texture on top. Use it for landing page heroes, sign-up screens, launch announcements or any section that needs color without images.

How it works

The root section.agb-hero paints a five-stop linear-gradient built from --agb-color-1 to --agb-color-4 (the first color repeats at the end so the loop has no hard edge). The gradient is four times larger than the section (background-size: 400% 400%), and the agb-shift keyframes move its background-position back and forth with animation-direction: alternate. Only the visible window of the gradient changes, so the colors appear to flow.

Behind the content, .agb-blobs holds three .agb-blob circles. The wrapper applies filter: blur(60px), each blob uses mix-blend-mode: soft-light, and the agb-float keyframes translate and scale them. Negative animation-delay values put the blobs out of phase from the first frame. .agb-grain overlays an inline SVG feTurbulence noise at low opacity, which hides gradient banding on large screens. The section uses isolation: isolate, so the negative z-index layers stay inside it.

The content block .agb-content holds an eyebrow pill, the heading, a lead paragraph and two buttons (.agb-btn--solid and .agb-btn--ghost), which stack on phones and sit side by side from 560px. No JavaScript is needed.

Customization

  • --agb-color-1 to --agb-color-4 on .agb-hero: replace the palette; the blobs reuse colors 1 and 4, so they follow automatically.
  • --agb-speed: the duration of one gradient sweep (default 18s); lower values make the motion livelier.
  • --agb-blob-speed: how fast the blurred blobs drift (default 24s).
  • --agb-angle: the direction of the gradient, e.g. 45deg for a diagonal from bottom left.
  • --agb-min-height: the minimum height of the section (default 100vh, a full-screen hero); use 36rem for a shorter banner.
  • Change opacity on .agb-grain to 0 to remove the noise, or raise it for a more textured, print-like look.
  • Delete the .agb-blobs element if you only want the flowing gradient.

Use cases

  • Landing page heroes: a slowly shifting coral, pink, violet and teal gradient fills the first screen
  • Sign-up screens: blurred drifting blobs and grain give color without any image files
  • Launch announcements: a headline, lead text and two buttons sit on top of the gradient
  • Short banners: the section height can be reduced from full screen to a compact strip

Accessibility

The section is labelled by its heading through aria-labelledby="agb-title". The blob and grain layers are decorative and marked aria-hidden="true". Headline text carries a soft text-shadow so the white type stays readable over the lighter coral and teal stops; check contrast again if you swap in pale colors. Both buttons show a white :focus-visible outline with an offset. With prefers-reduced-motion: reduce the gradient and blob animations stop and the gradient stays still, and the hover lift on the buttons is disabled.

Usage notes

Animating background-position is cheap for one hero, but avoid running many large animated gradients on the same page. Several .agb-hero sections can coexist; give each its own colors by overriding the custom properties on a modifier class.

Animated Gradient Background at a glance

Framework
Pure CSS
Code
HTML, CSS
JavaScript
Not needed, CSS only
Dependencies
None
Layout
Responsive, works on mobile
Category
Backgrounds
License
Free for personal and commercial use

Questions about this template

Can I use the Animated Gradient Background code for free?

Yes. You can copy or download the code and use it in personal and commercial projects, including client work. No sign-up is needed. Reselling it as part of a component library or template collection is not allowed; see the license.

How do I add it to my website?

There is nothing to install. Paste the HTML where the component should appear and add the CSS to your stylesheet. Download HTML gives you a complete page with everything already linked.

Does it need jQuery or a JavaScript framework?

No. It is built with HTML and CSS only, so there is no JavaScript to load.

Does it work on mobile?

Yes. The layout adapts to small screens. Use the Mobile and Tablet buttons above the live demo to check it at phone and tablet width.

Requirements

No dependencies. Pure HTML, CSS and JavaScript.

Animated Gradient Background – free Pure CSS background template
Animated Gradient Background · free Pure CSS background template

More Backgrounds

Animated Blob Background – free Pure CSS background template

Animated Blob Background

Pure CSS animated background with blurred, morphing color blobs drifting behind a hero headline, with a pause button and reduced-motion support.

Background Image Slideshow – free Bootstrap 5 background template

Background Image Slideshow

Bootstrap 5 hero section whose background cross-fades through photos with a slow zoom, progress dots, captions and a pause button.

CSS Pattern Backgrounds – free Pure CSS background template

CSS Pattern Backgrounds

Eight pure CSS gradient background patterns (dots, polka, grid, graph paper, stripes, crosshatch, checkerboard, zigzag) with a live scale slider.