Moire
import { useEffect, useRef } from 'react';
const css = `
.btn-moire {
--x: 30%;
--y: 50%;
position: relative;
display: grid;
place-items: center;
width: 220px;
height: 64px;
padding: 0;
border: 1px solid light-dark(#dbdde1, #2e3035);
border-radius: 16px;
background: light-dark(#fbfcfd, #121417);
color: light-dark(#373a40, #f1f2f3);
font-family: inherit;
font-size: 14px;
font-weight: 600;
letter-spacing: 0.05em;
cursor: pointer;
overflow: hidden;
}
.btn-moire:focus-visible { outline: 2px solid light-dark(#42454c, #e5e6e9); outline-offset: 3px; }
/* Two identical ring gratings; where their centres differ, the overlap beats into fringes. */
.btn-moire::before, .btn-moire::after {
content: '';
position: absolute;
inset: 0;
pointer-events: none;
}
.btn-moire::before {
background: repeating-radial-gradient(circle at 50% 50%, light-dark(#5f626a, #a7abb2) 0 1px, transparent 1px 6px);
opacity: 0.55;
}
.btn-moire::after {
background: repeating-radial-gradient(circle at var(--x) var(--y), light-dark(#5f626a, #a7abb2) 0 1px, transparent 1px 6px);
opacity: 0.55;
}
.btn-moire__label {
position: relative;
z-index: 1;
padding: 5px 14px;
border-radius: 999px;
background: light-dark(#fbfcfd, #121417);
box-shadow: 0 0 0 1px light-dark(#dbdde1, #2e3035);
}
`;
export function MoireButton() {
const btn = useRef<HTMLButtonElement>(null);
const pointer = useRef<{ x: number; y: number } | null>(null);
// At rest the second centre circles slowly; under the cursor it follows it (eased).
useEffect(() => {
const el = btn.current!;
const still = matchMedia('(prefers-reduced-motion: reduce)').matches;
let x = 0.3;
let y = 0.5;
let raf = 0;
const tick = (now: number) => {
const t = now / 1000;
const target = pointer.current ?? { x: 0.5 + Math.cos(t * 0.6) * 0.22, y: 0.5 + Math.sin(t * 0.9) * 0.3 };
x += (target.x - x) * 0.12;
y += (target.y - y) * 0.12;
el.style.setProperty('--x', `${(x * 100).toFixed(2)}%`);
el.style.setProperty('--y', `${(y * 100).toFixed(2)}%`);
raf = requestAnimationFrame(tick);
};
if (!still) raf = requestAnimationFrame(tick);
return () => cancelAnimationFrame(raf);
}, []);
return (
<>
<style>
{css}
</style>
<button
ref={btn}
type="button"
className="btn-moire"
onPointerMove={(e) => {
const r = btn.current!.getBoundingClientRect();
pointer.current = { x: (e.clientX - r.left) / r.width, y: (e.clientY - r.top) / r.height };
}}
onPointerLeave={() => (pointer.current = null)}
>
<span className="btn-moire__label">Interfere</span>
</button>
</>
);
}Markup where the component goes, CSS in your stylesheet, script before </body>. In Vue, Svelte or Angular, call initBtnMoire(el) on the mounted element instead.
<button type="button" class="btn-moire">
<span class="btn-moire__label">Interfere</span>
</button>.btn-moire {
--x: 30%;
--y: 50%;
position: relative;
display: grid;
place-items: center;
width: 220px;
height: 64px;
padding: 0;
border: 1px solid light-dark(#dbdde1, #2e3035);
border-radius: 16px;
background: light-dark(#fbfcfd, #121417);
color: light-dark(#373a40, #f1f2f3);
font-family: inherit;
font-size: 14px;
font-weight: 600;
letter-spacing: 0.05em;
cursor: pointer;
overflow: hidden;
}
.btn-moire:focus-visible { outline: 2px solid light-dark(#42454c, #e5e6e9); outline-offset: 3px; }
/* Two identical ring gratings; where their centres differ, the overlap beats into fringes. */
.btn-moire::before, .btn-moire::after {
content: '';
position: absolute;
inset: 0;
pointer-events: none;
}
.btn-moire::before {
background: repeating-radial-gradient(circle at 50% 50%, light-dark(#5f626a, #a7abb2) 0 1px, transparent 1px 6px);
opacity: 0.55;
}
.btn-moire::after {
background: repeating-radial-gradient(circle at var(--x) var(--y), light-dark(#5f626a, #a7abb2) 0 1px, transparent 1px 6px);
opacity: 0.55;
}
.btn-moire__label {
position: relative;
z-index: 1;
padding: 5px 14px;
border-radius: 999px;
background: light-dark(#fbfcfd, #121417);
box-shadow: 0 0 0 1px light-dark(#dbdde1, #2e3035);
}function initBtnMoire(root) {
if (matchMedia('(prefers-reduced-motion: reduce)').matches) return;
var pointer = null;
var x = 0.3;
var y = 0.5;
var raf = 0;
// At rest the second centre circles slowly; under the cursor it follows it, eased.
function tick(now) {
var t = now / 1000;
var target = pointer || { x: 0.5 + Math.cos(t * 0.6) * 0.22, y: 0.5 + Math.sin(t * 0.9) * 0.3 };
x += (target.x - x) * 0.12;
y += (target.y - y) * 0.12;
root.style.setProperty('--x', (x * 100).toFixed(2) + '%');
root.style.setProperty('--y', (y * 100).toFixed(2) + '%');
raf = requestAnimationFrame(tick);
}
function move(e) {
var r = root.getBoundingClientRect();
pointer = { x: (e.clientX - r.left) / r.width, y: (e.clientY - r.top) / r.height };
}
function leave() { pointer = null; }
root.addEventListener('pointermove', move);
root.addEventListener('pointerleave', leave);
raf = requestAnimationFrame(tick);
return function () {
cancelAnimationFrame(raf);
root.removeEventListener('pointermove', move);
root.removeEventListener('pointerleave', leave);
};
}
document.querySelectorAll('.btn-moire').forEach(initBtnMoire);Goal: Create a "Moire" button.
Visual behavior: Two identical ring gratings overlap inside the button. One centre circles slowly by itself and follows the cursor on hover, so the overlap beats into moving op-art fringes around the label.
Technique:
- ::before and ::after are both repeating-radial-gradients of thin rings (1px line every 6px) at 55% opacity; one is centred, the other at --x / --y.
- Where the two centres differ, the rings interfere into moire fringes that sweep as the centre moves.
- A rAF loop eases the second centre toward a slow Lissajous path at rest, or toward the cursor while it is over the button.
- The label sits on a solid pill so it stays readable over the pattern.
Accessibility: A real <button> with a visible label; decoration is aria-hidden. Focus outline. Under prefers-reduced-motion the pattern holds still.
My stack: {{USER_STACK}}
My styling: {{USER_STYLING}}
My constraints: {{USER_CONSTRAINTS}}
My colors: neutral only. Black, white and grays, no hues. Use the color values above as written, or my project's closest neutral tokens.
Return a single self-contained component. No dependencies.Goal: Create a "Moire" button.
Visual behavior: Two identical ring gratings overlap inside the button. One centre circles slowly by itself and follows the cursor on hover, so the overlap beats into moving op-art fringes around the label.
Technique:
- ::before and ::after are both repeating-radial-gradients of thin rings (1px line every 6px) at 55% opacity; one is centred, the other at --x / --y.
- Where the two centres differ, the rings interfere into moire fringes that sweep as the centre moves.
- A rAF loop eases the second centre toward a slow Lissajous path at rest, or toward the cursor while it is over the button.
- The label sits on a solid pill so it stays readable over the pattern.
Accessibility: A real <button> with a visible label; decoration is aria-hidden. Focus outline. Under prefers-reduced-motion the pattern holds still.
My stack: {{USER_STACK}}
My styling: {{USER_STYLING}}
My constraints: {{USER_CONSTRAINTS}}
My colors: use my project's existing color tokens. The color values above are grayscale placeholders. Map each one by its role (surface, text, border, accent, glow) to my theme, and keep their relative lightness so contrast and the effect still read.
Return a single self-contained component. No dependencies.Paste into Claude, ChatGPT or Cursor after filling in {{USER_STACK}}, {{USER_STYLING}} and {{USER_CONSTRAINTS}}. Neutral keeps the greys you see here; Match my project asks the model to map them onto your own colour tokens.
Free to use in any project, commercial included. MIT-0, no attribution required. Licence
About this component
Two identical ring gratings overlap inside the button. One centre circles slowly by itself and follows the cursor on hover, so the overlap beats into moving op-art fringes around the label.
- Dependencies
- None
- Difficulty
- Intermediate
- Triggers
- hover, mouse tracking, continuous, ambient
- Techniques
- radial gradient, pseudo elements, css variables, raf
- Reduced motion
- Respected
- Theme
- Light and dark (follows your page's color-scheme)
A real <button> with a visible label; decoration is aria-hidden. Focus outline. Under prefers-reduced-motion the pattern holds still.