Test365i
365i.co.uk
Back to all guides
CSS

An animated aurora background on an Elementor 4 div block

An aurora background is soft coloured light drifting behind a hero. This guide builds it from three CSS radial gradients on a single Elementor 4 div block, the same layer behind every hero, closing band and menu panel on this site, with no images and no JavaScript.

20 minutesCustom codeElementor

Works on WordPress 7.2, Elementor 4.4.2 and Elementor Pro 4.4.2; works in every current browser

Editorial integrity: read our editorial standards.

Live demo, running the code from this guide on a bare page with no theme styles.
  1. Make the hero a stacking context

    The light sits behind the content but inside the hero, so the hero needs three things: position: relative so the light can be placed inside it, overflow: hidden so the blurred edges do not spill onto the next section, and isolation: isolate so a negative z-index stays inside the hero instead of sinking behind the page.

    The dark background matters too. Light reads as light only against something darker, which is why the aurora on this site sits on #080813.

    Without the three rules the light sinks behind the page; with position, overflow and isolation it stays behind the text
    Three rules keep the light inside the hero.
    aurora.cssCSS
    .hero {
    	position: relative;
    	overflow: hidden;
    	isolation: isolate;
    	background: #080813;
    }
  2. Paint three radial gradients on one layer

    One absolutely positioned layer carries all three lights as stacked radial-gradient() backgrounds: violet, indigo and pink, each placed with at x% y% and fading to transparent by 70%. The layer is larger than the hero (the negative inset and 120% height) so the blur never shows a hard edge.

    filter: blur(70px) turns three blobs into light, and 90% opacity stops it overpowering the text. These are the exact values in the lab-aurora class on this site.

    Three radial gradients in violet, indigo and pink, first sharp and then softened by a blur filter
    The same three gradients, before and after the blur.
    aurora.cssCSS
    .aurora-bg {
    	position: absolute;
    	inset: -25% -15% auto -15%;
    	height: 120%;
    	z-index: -1;
    	pointer-events: none;
    	opacity: 0.9;
    	filter: blur(70px);
    	background-image:
    		radial-gradient(32% 38% at 28% 30%, #7453FE 0%, transparent 70%),
    		radial-gradient(28% 34% at 72% 26%, #3F4BDA 0%, transparent 70%),
    		radial-gradient(26% 30% at 56% 62%, #F93CBB 0%, transparent 70%);
    }
    After step 2: three blurred lights behind the headline, standing still.

    Josh W. Comeau explains why gradients between two strong colours can turn grey in the middle:

    By mixing two highly-saturated colors together, we wind up with a totally-desaturated color.

    Josh W. Comeau, Make Beautiful Gradients in CSS

    That is the reason each light fades to transparent rather than into its neighbour. The colours never mix with each other inside one gradient; they overlap as separate layers over a dark background, and the blur blends them as light. The result stays saturated where a single violet-to-pink gradient would have greyed in the middle.

  3. Let the light drift with @keyframes

    The drift moves the whole layer a few per cent, rotates it a few degrees and scales it slightly. Only transform changes, which browsers can animate without re-laying out the page, and alternate plays it forwards then backwards so there is never a jump.

    When I built this site, Elementor 4 did not keep animation properties inside a global class, so the keyframes and the animation line live in one Custom Code snippet (Elementor > Custom Code, location <head>). Without Elementor Pro, Appearance > Customize > Additional CSS does the same job. The gradients themselves can stay in the class.

    aurora.cssCSS
    @keyframes aurora-drift {
    	0% { transform: translate3d(-3%, 2%, 0) rotate(0deg) scale(1); }
    	50% { transform: translate3d(3%, -3%, 0) rotate(6deg) scale(1.06); }
    	100% { transform: translate3d(-1%, -5%, 0) rotate(-4deg) scale(1.02); }
    }
    
    .aurora-bg {
    	animation: aurora-drift 18s ease-in-out infinite alternate;
    	will-change: transform;
    }
    After step 3: the layer drifts and turns a few degrees over 18 seconds, then eases back.
  4. Build the hero in Elementor 4

    Give the hero container the class hero. Add a Div Block as its first child, leave it empty and give it the class aurora-bg. Your heading and text go after it. Elementor 4 prints a global class under the name you give it, so the CSS finds both elements with no extra selectors.

    On this site the same class sits behind every hero, the closing band on each page and the five panels of the mega menu, which you can see on the Test365i home page and in the Elementor 4 element gallery. The HTML below is the same structure outside Elementor:

    A section div block with the hero class holding an empty aurora-bg div block, a heading and a paragraph
    Two classes and one empty div block; the animation lives in Custom Code.
    index.htmlHTML
    <section class="hero">
    	<div class="aurora-bg"></div>
    	<h1>Your headline</h1>
    	<p>Your supporting line.</p>
    </section>
  5. Calm it for people who prefer less motion

    A drifting background is movement nobody asked for, so it should stop for anyone whose device asks for reduced motion. The light stays; only the drift goes. The spinning gradient border uses the same rule.

    aurora.cssCSS
    @media (prefers-reduced-motion: reduce) {
    	.aurora-bg { animation: none; }
    }
    The finished aurora. Turn on Reduce motion in your device settings and the lights stop drifting.

    MDN describes what the reduced-motion media query reports:

    Indicates that a user has enabled the setting on their device for reduced motion.

    MDN Web Docs, prefers-reduced-motion reference

    It is a setting the visitor chose, often because movement makes them unwell. Respecting it costs three lines and loses nothing that matters: the aurora still frames the hero, it just stops moving.

What the aurora background does not do

It needs a dark background. On white, three blurred gradients look like smudges rather than light.

A large filter: blur() layer costs some painting work. One aurora per section is fine; dozens of animated ones on a long page are not.

It is decoration. Keep text contrast measured against the darkest and the brightest part of the light, as this site does.

All the aurora background code

Each file below is complete. Copy it, or download it under the name shown.

aurora.cssCSS
.hero {
	position: relative;
	overflow: hidden;
	isolation: isolate;
	background: #080813;
}

.aurora-bg {
	position: absolute;
	inset: -25% -15% auto -15%;
	height: 120%;
	z-index: -1;
	pointer-events: none;
	opacity: 0.9;
	filter: blur(70px);
	background-image:
		radial-gradient(32% 38% at 28% 30%, #7453FE 0%, transparent 70%),
		radial-gradient(28% 34% at 72% 26%, #3F4BDA 0%, transparent 70%),
		radial-gradient(26% 30% at 56% 62%, #F93CBB 0%, transparent 70%);
}

@keyframes aurora-drift {
	0% { transform: translate3d(-3%, 2%, 0) rotate(0deg) scale(1); }
	50% { transform: translate3d(3%, -3%, 0) rotate(6deg) scale(1.06); }
	100% { transform: translate3d(-1%, -5%, 0) rotate(-4deg) scale(1.02); }
}

.aurora-bg {
	animation: aurora-drift 18s ease-in-out infinite alternate;
	will-change: transform;
}

@media (prefers-reduced-motion: reduce) {
	.aurora-bg { animation: none; }
}
index.htmlHTML
<section class="hero">
	<div class="aurora-bg"></div>
	<h1>Your headline</h1>
	<p>Your supporting line.</p>
</section>

Aurora background questions

Does the aurora background need JavaScript?

No. It is three CSS radial gradients, a blur filter and a keyframe animation.

Can I change the colours?

Yes. Swap the three colour values in the radial-gradient() lines. Keep each one fading to transparent so they do not mix into grey.

Why is the layer bigger than the hero?

A blur fades the edges of whatever it blurs. Making the layer larger than the hero and clipping it with overflow: hidden keeps the visible edges soft.

Will the animation hurt page speed?

It animates only transform, so it does not shift layout. This site scores 100 for performance on mobile with an aurora on every page.

Can I use it in Elementor without Elementor Pro?

Yes. The gradients can go in the class, and the keyframes go in Appearance > Customize > Additional CSS instead of Custom Code.

Does it work on a light background?

Not well. Light only reads as light against something darker, so it suits dark sections.

How do I stop it moving for some visitors?

The prefers-reduced-motion media query in step 5 stops the drift for anyone whose device asks for less motion.

Can I add a matching glow to cards on top?

Yes. A soft coloured box-shadow picks up the aurora colours. Box Shadow Generator, made by Mark McNeece of 365i, builds one you can copy.

Sources

  1. MDN Web Docs: radial-gradient()
  2. MDN Web Docs: prefers-reduced-motion
  3. Josh W. Comeau: Make Beautiful Gradients in CSS

More build guides

The latest guides, newest first.

Elementor

A clickable card grid with the Elementor 4 Collection loop

The Elementor 4 Collection loop repeats one design for every post a query finds. On this site it lists the build guides, which are a JetEngine post type, in the element gallery, the Lab and the mega menu, all from one card component. This guide builds that grid, makes each whole card clickable and hides fields that come back empty.

25 minutes Get the guide
Elementor

Style the Elementor 4 Carousel element: arrows, dots and loop

The Elementor 4 Carousel element gives you slides, arrows and dots as separate atomic parts. Out of the box on this site, the arrows sat on top of the slide titles, the active dot was black on a dark panel and Loop did nothing. This guide fixes all three, with the CSS the element gallery now runs.

20 minutes Get the guide
Elementor

The Elementor 4 Accordion element, built on native details

The Elementor 4 Accordion element is built on the browser's own details and summary elements, so it opens and closes with no script. This guide sets it up the way the element gallery on this site does, styles it with classes, and explains the FAQ schema switch and what Google now does with it.

15 minutes Get the guide