webdevpuneet.com

Dot Pattern — Free HTML CSS JS Dotted Background Snippet

Dot Pattern · Animations · Plain HTML, CSS & JS · Live preview

CategoryAnimations

Copy & paste

Source Code

<section class="dp-hero" id="dpHero">
  <div class="dp-dots" aria-hidden="true"></div>
  <div class="dp-spot" id="dpSpot" aria-hidden="true"></div>
  <div class="dp-content">
    <span class="dp-tag">◇ Infrastructure</span>
    <h1>Quietly powerful</h1>
    <p>A subtle dot grid backdrop with a glow that follows your cursor — one element, pure CSS.</p>
  </div>
</section>

Extend with AI

Take This Snippet Further With AI

The AI prompt for this one is for Patreon supporters ($3 a month, 7 days free), along with a site with no ads. Supporters enter the passcode once and it is remembered in this browser.

· Become a supporter

What's included

Features

One-element dot grid
A tiled radial-gradient, no image.
Edge-fade mask
Dots dissolve into the page.
Cursor spotlight
A masked accent layer follows the pointer.
Aligned bright dots
Shared tiling lines up the two grids.
CSS-variable reveal
--x/--y move the mask cheaply.
No per-frame JS
The handler only sets two properties.
Click-through content
Dots light under the headline.
Scales to any size
Masking needs no extra work.

About this UI Snippet

Dot Pattern — Dotted Backdrop With a Cursor Spotlight

Screenshot of the Dot Pattern snippet rendered live

The dot pattern is the understated technical backdrop on infrastructure and developer sites: a faint grid of dots, calm at rest, with a soft glow that follows your cursor and lights up brighter, colored dots in its radius. This snippet builds the whole thing with pure CSS backgrounds and masks, plus two lines of JavaScript to move the spotlight — no canvas, no images.

The dot grid in one element

The base dots are a single radial-gradient — a 1px white dot over transparent — tiled across the hero with background-size: 22px 22px. That repeats the dot on a regular grid, giving graph-paper dots from one background declaration. A mask-image radial gradient then fades the dots toward the edges so the pattern dissolves into the page rather than ending at a hard border, keeping focus on the center.

The cursor spotlight

The interactive glow is a second dot layer, .dp-spot, identical in tiling but in a brighter accent color. It is revealed through a mask-image radial gradient whose center is driven by two CSS custom properties, --x and --y. A pointermove handler writes the cursor position into those variables, so the masked circle — and therefore the brighter dots — follows the pointer. Outside the circle the layer is masked away, so you only see the accent dots within the spotlight. The layer fades in on hover so the hero is monochrome and calm until you interact.

Two layers, one illusion

The effect of "dots lighting up under the cursor" is really two stacked dot grids: the faint base always visible, and the bright accent grid revealed only inside the moving mask. Because both share the same 22px tiling, the bright dots line up exactly over the faint ones, so it reads as the same dots brightening rather than a separate layer. This alignment is what sells it.

Cheap and smooth

There is no per-frame JavaScript — the handler only sets two CSS variables, and the browser composites the masked gradient move on the GPU. So the spotlight tracks the cursor smoothly with negligible cost, even on a large hero. The content sits above with pointer-events: none (except where you need clicks), so moving over the headline still lights the dots beneath.

Why masks beat redrawing

Some implementations redraw dots on a canvas each frame to brighten those near the cursor. Masking a pre-tiled gradient is far cheaper and pixel-perfect: the dots never shift, and the only thing moving is a mask center, which is a single composited property. It also scales to any hero size without more work.

Customizing it

Change background-size for a denser or sparser grid, the dot color and size, the spotlight radius (the 200px circle in the mask), or the edge-fade mask shape. Recolor the accent dots to your brand. Pair it with an aurora text headline or a particle network for a layered, modern hero.

Step by step

How to Use

  1. 1
    Paste HTML, CSS, and JSA faint dotted grid fills the hero behind the text.
  2. 2
    Move your cursorA glow follows the pointer and brightens nearby dots.
  3. 3
    Note the edge fadeThe dots dissolve toward the edges of the hero.
  4. 4
    Hover the headlineThe dots still light up beneath the text.
  5. 5
    Resize the gridChange background-size for denser or sparser dots.
  6. 6
    Recolor the spotlightEdit the accent dot color and radius.

Real-world uses

Common Use Cases

Developer tool hero backdrops
Place a faint dotted grid behind an aurora text headline, with a cursor spotlight lighting up brighter, coloured dots in its radius.
Infrastructure and cloud sites
Pair with a particle network elsewhere on the page for a calm technical look, with dots dissolving at the edges through a mask.
Documentation landing pages
Frame a floating pill nav above an understated surface, using one tiled radial gradient and no image file.
SaaS feature sections
Set a quiet surface behind a feature tabs showcase, where shared tiling keeps the two dot grids perfectly aligned.
CSS mask reference
Study how a masked accent layer follows the pointer to reveal brighter dots, with an animated gradient CTA as a natural next section.
Related: Before/After Hero with Comparison Slider
See the Before/After Hero with Comparison Slider for a related heroes pattern worth pairing with this one.
Related: tsParticles Interactive Hero
See the tsParticles Interactive Hero for a related heroes pattern worth pairing with this one.
Related: Hero with Voice Input Waveform Demo
See the Hero with Voice Input Waveform Demo for a related heroes pattern worth pairing with this one.

Got questions?

Frequently Asked Questions

A single radial-gradient paints a 1px dot over transparent, tiled across the element with background-size: 22px 22px. That repeats the dot on a regular grid from one background declaration. A mask-image radial gradient then fades the dots toward the edges so the pattern dissolves into the page instead of stopping at a hard border.

A second dot layer in a brighter accent color is revealed through a mask-image radial gradient centered on the --x and --y CSS variables, which a pointermove handler updates to the cursor position. Only the dots inside the masked circle show, and because both layers share the same 22px tiling, the bright dots align exactly over the faint ones, so it reads as the same dots brightening.

Masking a pre-tiled gradient is cheaper and pixel-perfect: the dots never move, and the only thing changing is a mask center, a single composited property. A canvas approach would redraw dots every frame. The mask method scales to any hero size with no extra work and has negligible runtime cost.

Yes. There is no per-frame JavaScript — the pointermove handler only writes two CSS variables, and the browser composites the masked gradient move on the GPU. So the glow tracks the cursor smoothly even on a large hero, and the content above uses pointer-events: none so it still lights the dots beneath the headline.

Keep the dot grid and edge fade as static CSS. Attach a pointermove handler that sets the --x and --y inline style on the spotlight layer via a ref. No state is needed since the move only updates CSS variables. The masks port directly; in Tailwind use arbitrary bg-[radial-gradient(...)] and mask-image values with the inline variables.