Dot field hero
A hero section on a living grid of dots that swell and warm up around your cursor, and send out a shockwave when you click.
"use client";
import { useEffect, useRef, type ReactNode } from "react";
import "./dot-field-hero.css";
type DotFieldHeroProps = {
badge?: string;
title: ReactNode;
text: string;
primary: { label: string; href: string };
secondary?: { label: string; href: string };
note?: string;
theme?: "light" | "dark";
};
type Wave = { x: number; y: number; t: number };
/**
* DotFieldHero
* - A <canvas> behind the content draws a grid of dots.
* - Dots near the pointer grow and shift toward the accent color.
* - Clicking (or tapping) sends a ring-shaped shockwave across the grid.
* - The animation only runs while something is moving, so an idle hero costs nothing.
*/
export function DotFieldHero({
badge,
title,
text,
primary,
secondary,
note,
theme = "light",
}: DotFieldHeroProps) {
const section = useRef<HTMLElement>(null);
const canvas = useRef<HTMLCanvasElement>(null);
useEffect(() => {
const host = section.current;
const cv = canvas.current;
const ctx = cv?.getContext("2d");
if (!host || !cv || !ctx) return;
const reduce = matchMedia("(prefers-reduced-motion: reduce)").matches;
const css = getComputedStyle(host);
const dot = css.getPropertyValue("--dot").trim() || "#0e0e10";
const hot = css.getPropertyValue("--accent").trim() || "#ff5a1f";
const GAP = 26;
const RADIUS = 150; // how far the cursor glow reaches
let w = 0,
h = 0,
dpr = 1,
raf = 0;
let px = -9999,
py = -9999,
glow = 0,
glowTarget = 0;
const waves: Wave[] = [];
const resize = () => {
dpr = Math.min(devicePixelRatio || 1, 2);
w = host.clientWidth;
h = host.clientHeight;
cv.width = w * dpr;
cv.height = h * dpr;
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
draw(performance.now());
};
const draw = (now: number) => {
ctx.clearRect(0, 0, w, h);
glow += (glowTarget - glow) * 0.12;
for (let x = GAP / 2; x < w; x += GAP) {
for (let y = GAP / 2; y < h; y += GAP) {
// Cursor influence: 1 at the pointer, 0 at RADIUS.
const d = Math.hypot(x - px, y - py);
let k = Math.max(0, 1 - d / RADIUS) * glow;
// Shockwaves: a thin ring that travels outward and fades.
for (const wv of waves) {
const age = (now - wv.t) / 1000;
const ring = age * 520;
const dd = Math.abs(Math.hypot(x - wv.x, y - wv.y) - ring);
if (dd < 40)
k = Math.max(k, (1 - dd / 40) * Math.max(0, 1 - age / 1.4));
}
ctx.globalAlpha = 0.22 + k * 0.78;
ctx.fillStyle = k > 0.15 ? hot : dot;
ctx.beginPath();
ctx.arc(x, y, 1.3 + k * 2.6, 0, Math.PI * 2);
ctx.fill();
}
}
ctx.globalAlpha = 1;
};
const loop = (now: number) => {
while (waves.length && now - waves[0].t > 1400) waves.shift();
draw(now);
const settling = Math.abs(glowTarget - glow) > 0.01;
raf =
waves.length || settling || glowTarget > 0
? requestAnimationFrame(loop)
: 0;
};
const kick = () => {
if (!raf) raf = requestAnimationFrame(loop);
};
const onMove = (e: PointerEvent) => {
const r = host.getBoundingClientRect();
px = e.clientX - r.left;
py = e.clientY - r.top;
if (e.pointerType === "mouse") glowTarget = 1;
kick();
};
const onLeave = () => {
glowTarget = 0;
kick();
};
const onDown = (e: PointerEvent) => {
const r = host.getBoundingClientRect();
waves.push({
x: e.clientX - r.left,
y: e.clientY - r.top,
t: performance.now(),
});
kick();
};
const ro = new ResizeObserver(resize);
ro.observe(host);
if (!reduce) {
host.addEventListener("pointermove", onMove);
host.addEventListener("pointerleave", onLeave);
host.addEventListener("pointerdown", onDown);
}
return () => {
cancelAnimationFrame(raf);
ro.disconnect();
host.removeEventListener("pointermove", onMove);
host.removeEventListener("pointerleave", onLeave);
host.removeEventListener("pointerdown", onDown);
};
}, [theme]);
return (
<section ref={section} className="gu-dothero" data-theme={theme}>
<canvas ref={canvas} className="gu-dothero__canvas" aria-hidden="true" />
<div className="gu-dothero__content">
{badge && <p className="gu-dothero__badge">{badge}</p>}
<h1 className="gu-dothero__title">{title}</h1>
<p className="gu-dothero__text">{text}</p>
<div className="gu-dothero__actions">
<a className="gu-dothero__btn" href={primary.href}>
{primary.label}
</a>
{secondary && (
<a
className="gu-dothero__btn gu-dothero__btn--ghost"
href={secondary.href}
>
{secondary.label}
</a>
)}
</div>
{note && <p className="gu-dothero__note">{note}</p>}
</div>
</section>
);
}
Paste this into ChatGPT, Claude, Cursor, v0, Lovable or Bolt. It describes the layout, motion, colors and accessibility and includes the code, so the AI can rebuild it in any framework.
# Build this UI piece: Dot field hero
You are a senior front-end engineer. Recreate the piece below in my project. If I don't say which framework I use, ask once, then build it in that framework (React, Vue, Svelte, Angular, Astro, plain HTML/CSS/JS or anything else). Keep the behavior, motion, colors, spacing and accessibility exactly as described. Keep the code clean and commented for beginners.
## What it is
A full-width hero section on top of a canvas grid of small dots. Dots near the cursor grow and turn the accent color, and a click or tap sends a ring-shaped shockwave across the grid.
## Layout and look
- Section: min height 640px, background #f3eee3 (dark #0e0e10), centered content, max width 820px.
- Dots: every 26px, radius 1.3px at 22% opacity in the text color.
- Content: a pill badge with an orange (#ff5a1f) live dot and halo; a huge headline (clamp to ~6.4rem, weight 900, line-height 0.92, letter-spacing -0.05em) where an <em> word is orange; a muted paragraph; a solid orange pill button and an outlined pill button (54px tall); a small note line.
- A radial wash of the background color sits behind the text so it stays readable over the dots.
## Behavior and motion
1. Canvas sized to the section with devicePixelRatio (max 2), redrawn on resize.
2. Cursor influence k = max(0, 1 - distance/150) multiplied by a glow value that eases toward 1 on mouse move and 0 on leave. Dot radius = 1.3 + k × 2.6, opacity = 0.22 + k × 0.78; dots with k above 0.15 use the accent color.
3. Click/tap adds a wave: a ring with radius = age × 520px/s and 40px falloff, fading out over 1.4s; dots on the ring react like the cursor.
4. requestAnimationFrame only runs while glow is settling, the pointer is inside, or a wave is alive. Idle = no CPU.
## Touch
Taps create shockwaves (no hover glow on touch).
## Accessibility
- Canvas is aria-hidden; the content is regular HTML with an <h1>.
- Clear focus rings on buttons.
- prefers-reduced-motion: dots drawn once, no listeners.
## Props
badge, title (ReactNode, supports <em>), text, primary ({ label, href }), secondary, note, theme.
## Reference implementation
The original is written in React with one plain CSS file. Dependencies: none (plain React and CSS). Translate it faithfully; do not add new libraries unless my framework needs them.
### DotFieldHero.tsx
```tsx
"use client";
import { useEffect, useRef, type ReactNode } from "react";
import "./dot-field-hero.css";
type DotFieldHeroProps = {
badge?: string;
title: ReactNode;
text: string;
primary: { label: string; href: string };
secondary?: { label: string; href: string };
note?: string;
theme?: "light" | "dark";
};
type Wave = { x: number; y: number; t: number };
/**
* DotFieldHero
* - A <canvas> behind the content draws a grid of dots.
* - Dots near the pointer grow and shift toward the accent color.
* - Clicking (or tapping) sends a ring-shaped shockwave across the grid.
* - The animation only runs while something is moving, so an idle hero costs nothing.
*/
export function DotFieldHero({
badge,
title,
text,
primary,
secondary,
note,
theme = "light",
}: DotFieldHeroProps) {
const section = useRef<HTMLElement>(null);
const canvas = useRef<HTMLCanvasElement>(null);
useEffect(() => {
const host = section.current;
const cv = canvas.current;
const ctx = cv?.getContext("2d");
if (!host || !cv || !ctx) return;
const reduce = matchMedia("(prefers-reduced-motion: reduce)").matches;
const css = getComputedStyle(host);
const dot = css.getPropertyValue("--dot").trim() || "#0e0e10";
const hot = css.getPropertyValue("--accent").trim() || "#ff5a1f";
const GAP = 26;
const RADIUS = 150; // how far the cursor glow reaches
let w = 0,
h = 0,
dpr = 1,
raf = 0;
let px = -9999,
py = -9999,
glow = 0,
glowTarget = 0;
const waves: Wave[] = [];
const resize = () => {
dpr = Math.min(devicePixelRatio || 1, 2);
w = host.clientWidth;
h = host.clientHeight;
cv.width = w * dpr;
cv.height = h * dpr;
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
draw(performance.now());
};
const draw = (now: number) => {
ctx.clearRect(0, 0, w, h);
glow += (glowTarget - glow) * 0.12;
for (let x = GAP / 2; x < w; x += GAP) {
for (let y = GAP / 2; y < h; y += GAP) {
// Cursor influence: 1 at the pointer, 0 at RADIUS.
const d = Math.hypot(x - px, y - py);
let k = Math.max(0, 1 - d / RADIUS) * glow;
// Shockwaves: a thin ring that travels outward and fades.
for (const wv of waves) {
const age = (now - wv.t) / 1000;
const ring = age * 520;
const dd = Math.abs(Math.hypot(x - wv.x, y - wv.y) - ring);
if (dd < 40)
k = Math.max(k, (1 - dd / 40) * Math.max(0, 1 - age / 1.4));
}
ctx.globalAlpha = 0.22 + k * 0.78;
ctx.fillStyle = k > 0.15 ? hot : dot;
ctx.beginPath();
ctx.arc(x, y, 1.3 + k * 2.6, 0, Math.PI * 2);
ctx.fill();
}
}
ctx.globalAlpha = 1;
};
const loop = (now: number) => {
while (waves.length && now - waves[0].t > 1400) waves.shift();
draw(now);
const settling = Math.abs(glowTarget - glow) > 0.01;
raf =
waves.length || settling || glowTarget > 0
? requestAnimationFrame(loop)
: 0;
};
const kick = () => {
if (!raf) raf = requestAnimationFrame(loop);
};
const onMove = (e: PointerEvent) => {
const r = host.getBoundingClientRect();
px = e.clientX - r.left;
py = e.clientY - r.top;
if (e.pointerType === "mouse") glowTarget = 1;
kick();
};
const onLeave = () => {
glowTarget = 0;
kick();
};
const onDown = (e: PointerEvent) => {
const r = host.getBoundingClientRect();
waves.push({
x: e.clientX - r.left,
y: e.clientY - r.top,
t: performance.now(),
});
kick();
};
const ro = new ResizeObserver(resize);
ro.observe(host);
if (!reduce) {
host.addEventListener("pointermove", onMove);
host.addEventListener("pointerleave", onLeave);
host.addEventListener("pointerdown", onDown);
}
return () => {
cancelAnimationFrame(raf);
ro.disconnect();
host.removeEventListener("pointermove", onMove);
host.removeEventListener("pointerleave", onLeave);
host.removeEventListener("pointerdown", onDown);
};
}, [theme]);
return (
<section ref={section} className="gu-dothero" data-theme={theme}>
<canvas ref={canvas} className="gu-dothero__canvas" aria-hidden="true" />
<div className="gu-dothero__content">
{badge && <p className="gu-dothero__badge">{badge}</p>}
<h1 className="gu-dothero__title">{title}</h1>
<p className="gu-dothero__text">{text}</p>
<div className="gu-dothero__actions">
<a className="gu-dothero__btn" href={primary.href}>
{primary.label}
</a>
{secondary && (
<a
className="gu-dothero__btn gu-dothero__btn--ghost"
href={secondary.href}
>
{secondary.label}
</a>
)}
</div>
{note && <p className="gu-dothero__note">{note}</p>}
</div>
</section>
);
}
```
### dot-field-hero.css
```css
/* DotFieldHero: change these colors to match your brand. */
.gu-dothero {
--bg: #f3eee3;
--text: #0e0e10;
--muted: #57534b;
--dot: #0e0e10; /* resting dots */
--accent: #ff5a1f; /* dots near the cursor + main button */
--accent-text: #0e0e10;
--line: rgb(14 14 16 / 0.18);
--focus: #2b35ff;
container-type: inline-size;
position: relative;
display: grid;
place-items: center;
min-height: 640px;
overflow: hidden;
padding: 96px 24px;
background: var(--bg);
color: var(--text);
font-family: system-ui, sans-serif;
text-align: center;
touch-action: manipulation;
}
.gu-dothero[data-theme="dark"] {
--bg: #0e0e10;
--text: #f3eee3;
--muted: #aea89c;
--dot: #f3eee3;
--line: rgb(243 238 227 / 0.2);
--focus: #d7ff3a;
}
.gu-dothero__canvas {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
}
/* A soft pool of background color behind the text keeps it readable over the dots. */
.gu-dothero__content {
position: relative;
max-width: 820px;
padding: 24px;
border-radius: 40px;
background: radial-gradient(closest-side, var(--bg) 60%, transparent);
pointer-events: none;
}
.gu-dothero__content a {
pointer-events: auto;
}
.gu-dothero__badge {
display: inline-flex;
align-items: center;
gap: 8px;
margin: 0 0 24px;
padding: 7px 14px;
border: 1px solid var(--line);
border-radius: 999px;
background: var(--bg);
font-size: 0.85rem;
font-weight: 700;
}
.gu-dothero__badge::before {
content: "";
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 25%, transparent);
}
.gu-dothero__title {
margin: 0;
font-size: clamp(2.8rem, 9cqi, 6.4rem);
font-weight: 900;
line-height: 0.92;
letter-spacing: -0.05em;
text-wrap: balance;
}
.gu-dothero__title em {
font-style: normal;
color: var(--accent);
}
.gu-dothero__text {
max-width: 34em;
margin: 24px auto 0;
color: var(--muted);
font-size: clamp(1.05rem, 2cqi, 1.25rem);
line-height: 1.5;
}
.gu-dothero__actions {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 12px;
margin-top: 36px;
}
.gu-dothero__btn {
display: inline-flex;
align-items: center;
min-height: 54px;
padding: 0 28px;
border-radius: 999px;
background: var(--accent);
color: var(--accent-text);
font-weight: 800;
text-decoration: none;
transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.gu-dothero__btn:hover {
transform: translateY(-2px);
}
.gu-dothero__btn--ghost {
border: 2px solid var(--text);
background: var(--bg);
color: var(--text);
}
.gu-dothero__btn:focus-visible {
outline: 3px solid var(--focus);
outline-offset: 3px;
}
.gu-dothero__note {
margin: 22px 0 0;
color: var(--muted);
font-size: 0.85rem;
}
@media (prefers-reduced-motion: reduce) {
.gu-dothero__btn {
transition: none;
}
}
```
You might also want
Next piece: Draggable bottom sheetContour map 3D hero
Components, advanced, needs three
Depth cards hero
Components, intermediate
Glass prism 3D hero
Components, advanced, needs three