Dot Pattern — Free HTML CSS JS Dotted Background Snippet
Dot Pattern · Animations · Plain HTML, CSS & JS · Live preview
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>*{box-sizing:border-box;margin:0;padding:0}
body{font-family:system-ui,-apple-system,sans-serif;background:#06060e;color:#fff}
.dp-hero{position:relative;min-height:100vh;overflow:hidden;display:flex;align-items:center;justify-content:center;text-align:center}
.dp-dots{position:absolute;inset:0;background-image:radial-gradient(rgba(255,255,255,.18) 1px,transparent 1px);background-size:22px 22px;
-webkit-mask-image:radial-gradient(ellipse at center,#000 30%,transparent 75%);
mask-image:radial-gradient(ellipse at center,#000 30%,transparent 75%)}
/* A coloured glow that reveals brighter dots under the cursor by overlaying a
second masked dot layer through the spotlight. */
.dp-spot{position:absolute;inset:0;pointer-events:none;background-image:radial-gradient(rgba(129,140,248,.9) 1px,transparent 1px);background-size:22px 22px;opacity:0;transition:opacity .3s;
-webkit-mask-image:radial-gradient(200px circle at var(--x,-200px) var(--y,-200px),#000 0%,transparent 70%);
mask-image:radial-gradient(200px circle at var(--x,-200px) var(--y,-200px),#000 0%,transparent 70%)}
.dp-hero:hover .dp-spot{opacity:1}
.dp-content{position:relative;z-index:1;padding:0 20px;max-width:600px;pointer-events:none}
.dp-tag{display:inline-block;font-size:12px;font-weight:700;letter-spacing:.05em;color:#c7d2fe;background:rgba(99,102,241,.16);border:1px solid rgba(99,102,241,.4);padding:6px 13px;border-radius:999px;margin-bottom:18px}
.dp-content h1{font-size:clamp(34px,7vw,64px);font-weight:900;letter-spacing:-.03em}
.dp-content p{margin-top:14px;font-size:16px;color:#9a9ac0;line-height:1.55}var hero = document.getElementById('dpHero');
var spot = document.getElementById('dpSpot');
// Move the spotlight mask to the cursor via two CSS variables — no per-frame
// JS work beyond setting properties.
hero.addEventListener('pointermove', function (e) {
var r = hero.getBoundingClientRect();
spot.style.setProperty('--x', (e.clientX - r.left) + 'px');
spot.style.setProperty('--y', (e.clientY - r.top) + 'px');
});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.
What's included
Features
About this UI Snippet
Dot Pattern — Dotted Backdrop With a Cursor Spotlight

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