Skip to content

Mesh Gradient Background

Soft multi-color mesh gradient hero made with layered CSS radial gradients, film grain and three switchable Tailwind palettes.

Also known as: gradient mesh background, aurora gradient background, blurred gradient hero, colorful gradient background, grainy gradient backdrop

Mesh Gradient Background live demo

Open in new tab

Tailwind CSS code (HTML, CSS, JS)

A soft, multi-color mesh gradient background built from layered CSS radial gradients, shown as a hero section with Tailwind CSS layout utilities and three switchable palettes. No images or canvas are involved, so it stays sharp at any size, weighs almost nothing and fits landing pages, SaaS heroes, sign-up screens and section backgrounds.

How it works

The root is section.mgb-hero. Behind the content sit two decorative layers marked aria-hidden="true": .mgb-mesh and .mgb-grain, both placed with absolute inset-0 -z-10 inside an isolate stacking context.

.mgb-mesh paints the base color --mgb-base and stacks five radial-gradient() layers on top, each one fading from a palette color (--mgb-c1 to --mgb-c5) to transparent at a different corner or the center. A large filter: blur(var(--mgb-blur)) melts the blobs into each other, and the oversized background-size is slowly moved by the mgb-drift keyframes so the colors breathe. .mgb-grain overlays a tiny inline SVG feTurbulence noise with mix-blend-mode: overlay, which removes color banding and gives a printed feel.

Each palette is just a set of custom properties on [data-mgb-palette="sunset"], "lagoon" or "aurora", including the text color --mgb-ink and the glass colors used by .mgb-glass. The colors are registered with @property as <color>, so switching palettes cross-fades smoothly. The script listens for click on every [data-mgb-set] button, writes the value into data-mgb-palette and updates aria-pressed. Without JavaScript the default palette simply stays in place.

Customization

  • --mgb-c1 … --mgb-c5 and --mgb-base in style.css: set your brand colors to create a new palette.
  • The at 12% 18% style positions inside .mgb-mesh: move a blob to another spot or remove a layer for a calmer mix.
  • --mgb-blur on .mgb-hero: lower it (for example 30px) for more defined color spots, raise it for a hazier look.
  • --mgb-speed on .mgb-hero: slow the drift down (for example 40s) or set animation: none on .mgb-mesh for a static background.
  • opacity: 0.18 on .mgb-grain: raise it for visible film grain or delete the .mgb-grain element for a perfectly smooth surface.
  • data-mgb-palette on .mgb-hero: start with lagoon or aurora (also move aria-pressed="true" to the matching button).
  • Add a palette by copying the [data-mgb-palette="aurora"] rule and adding a button with data-mgb-set and a .mgb-chip color.

Use cases

  • SaaS landing pages: a soft multi-color hero background gives a modern look without images
  • Product launches: three switchable palettes let you pick the mood that fits the brand
  • Portfolio headers: layered radial gradients with film grain add depth behind a headline
  • Event and app pages: a lightweight background made from gradients instead of heavy image files

Accessibility

The mesh and grain layers are hidden from assistive technology. Text and button colors come from --mgb-ink, which each palette sets to a dark or light value with strong contrast against its base. The palette switcher is a role="group" with an aria-label, and each option is a real button with aria-pressed, so screen readers announce the current choice. Links and buttons show a visible focus outline in the ink color, and the drift animation and color transitions are disabled under prefers-reduced-motion: reduce.

Usage notes

@property is supported in all current evergreen browsers; older browsers switch palettes instantly instead of fading. The demo links use href="#" and are blocked by the script; replace them with real URLs.

Mesh Gradient Background at a glance

Framework
Tailwind CSS
Code
HTML, CSS, JavaScript
JavaScript
Vanilla JavaScript, no jQuery
Dependencies
Tailwind CSS
Layout
Responsive, works on mobile
Category
Backgrounds
License
Free for personal and commercial use

Questions about this template

Can I use the Mesh 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?

Load Tailwind CSS from a CDN (the links are under Requirements). Paste the HTML where the component should appear, add the CSS to your stylesheet and load the JavaScript before the closing </body> tag. Download HTML gives you a complete page with everything already linked.

Does it need jQuery or a JavaScript framework?

No. The script is plain vanilla JavaScript, so it works without jQuery, React or Vue. You can still use the markup inside those frameworks.

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

Add these to your page (already included in the download):

  • <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>

The Tailwind browser build is for prototyping. In production, compile Tailwind with its CLI or your bundler.

Mesh Gradient Background – free Tailwind CSS background template
Mesh Gradient Background · free Tailwind 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.

Animated Gradient Background – free Pure CSS background template

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.