Maze
React + Tailwind
const css = `
@keyframes loader-maze-solve {
0% { stroke-dashoffset: 1; opacity: 1; }
70% { stroke-dashoffset: 0; opacity: 1; }
85% { stroke-dashoffset: 0; opacity: 1; }
100% { stroke-dashoffset: 0; opacity: 0; }
}
@keyframes loader-maze-goal {
0%, 66% { opacity: 0.35; transform: scale(1); }
72% { opacity: 1; transform: scale(1.8); }
85% { opacity: 1; transform: scale(1); }
100% { opacity: 0.35; }
}
.loader-maze { display: block; width: 96px; height: 96px; }
.loader-maze__walls { fill: none; stroke: light-dark(#6d7179, #7d8087); stroke-width: 0.1; stroke-linecap: square; }
.loader-maze__route {
fill: none;
stroke: light-dark(#373a40, #f1f2f3);
stroke-width: 0.16;
stroke-linecap: round;
stroke-linejoin: round;
stroke-dasharray: 1;
animation: loader-maze-solve 3s cubic-bezier(0.45, 0, 0.55, 1) infinite;
}
.loader-maze__goal {
fill: light-dark(#373a40, #f1f2f3);
transform-box: fill-box;
transform-origin: center;
animation: loader-maze-goal 3s ease infinite;
}
@media (prefers-reduced-motion: reduce) {
.loader-maze__route, .loader-maze__goal { animation: none; stroke-dashoffset: 0; }
}
`;
const N = 7;
/** A perfect maze (one route between any two cells) carved by a seeded depth-first walk. */
function carve() {
let seed = 11;
const rand = () => ((seed = (seed * 16807) % 2147483647) / 2147483647);
const open = new Set<string>(); // "a-b" passages between cell indexes
const seen = new Set<number>([0]);
const stack = [0];
while (stack.length) {
const c = stack[stack.length - 1];
const x = c % N;
const y = Math.floor(c / N);
const next = [
x > 0 && c - 1,
x < N - 1 && c + 1,
y > 0 && c - N,
y < N - 1 && c + N,
].filter((n): n is number => n !== false && !seen.has(n));
if (!next.length) {
stack.pop();
continue;
}
const n = next[Math.floor(rand() * next.length)];
open.add(`${Math.min(c, n)}-${Math.max(c, n)}`);
seen.add(n);
stack.push(n);
}
return open;
}
const OPEN = carve();
const isOpen = (a: number, b: number) => OPEN.has(`${Math.min(a, b)}-${Math.max(a, b)}`);
// Walls: the outer frame (with an entrance top-left and exit bottom-right) plus every closed side.
let WALLS = `M1 0H${N}V${N - 1}M${N - 1} ${N}H0V1`;
for (let y = 0; y < N; y++)
for (let x = 0; x < N; x++) {
const c = y * N + x;
if (x < N - 1 && !isOpen(c, c + 1)) WALLS += `M${x + 1} ${y}V${y + 1}`;
if (y < N - 1 && !isOpen(c, c + N)) WALLS += `M${x} ${y + 1}H${x + 1}`;
}
// The route: breadth-first from the first cell to the last, through open passages only.
function solve() {
const prev = new Map<number, number>([[0, -1]]);
const queue = [0];
while (queue.length) {
const c = queue.shift()!;
if (c === N * N - 1) break;
const x = c % N;
for (const n of [x > 0 ? c - 1 : -1, x < N - 1 ? c + 1 : -1, c - N, c + N]) {
if (n < 0 || n >= N * N || prev.has(n) || !isOpen(c, n)) continue;
prev.set(n, c);
queue.push(n);
}
}
const path: number[] = [];
for (let c = N * N - 1; c !== -1; c = prev.get(c)!) path.unshift(c);
return path;
}
const ROUTE =
'M0.5 -0.4' +
solve()
.map((c) => `L${(c % N) + 0.5} ${Math.floor(c / N) + 0.5}`)
.join('') +
`L${N - 0.5} ${N + 0.4}`;
export function MazeLoader() {
return (
<>
<style>
{css}
</style>
<svg className="loader-maze" viewBox={`-0.6 -0.6 ${N + 1.2} ${N + 1.2}`} role="status" aria-label="Loading">
<path className="loader-maze__walls" d={WALLS} />
<path className="loader-maze__route" d={ROUTE} pathLength={1} />
<circle className="loader-maze__goal" cx={N - 0.5} cy={N + 0.4} r={0.22} />
</svg>
</>
);
}Markup where the component goes, CSS in your stylesheet. No JavaScript.
HTML
<svg class="loader-maze" viewBox="-0.6 -0.6 8.2 8.2" role="status" aria-label="Loading">
<path class="loader-maze__walls" d="M1 0H7V6M6 7H0V1M0 1H1M1 1H2M2 1H3M3 1H4M5 0V1M1 2H2M4 1V2M3 2H4M4 2H5M6 1V2M5 2H6M1 2V3M1 3H2M3 2V3M2 3H3M5 2V3M6 3H7M1 4H2M2 4H3M4 3V4M3 4H4M4 4H5M6 3V4M5 4H6M1 4V5M2 5H3M3 5H4M5 4V5M1 5V6M1 6H2M2 6H3M4 5V6M5 5V6M6 5V6M4 6V7M6 6V7"></path>
<path class="loader-maze__route" d="M0.5 -0.4L0.5 0.5L1.5 0.5L2.5 0.5L3.5 0.5L4.5 0.5L4.5 1.5L5.5 1.5L5.5 0.5L6.5 0.5L6.5 1.5L6.5 2.5L5.5 2.5L5.5 3.5L4.5 3.5L4.5 2.5L3.5 2.5L3.5 3.5L2.5 3.5L1.5 3.5L0.5 3.5L0.5 4.5L0.5 5.5L0.5 6.5L1.5 6.5L2.5 6.5L3.5 6.5L3.5 5.5L2.5 5.5L1.5 5.5L1.5 4.5L2.5 4.5L3.5 4.5L4.5 4.5L4.5 5.5L4.5 6.5L5.5 6.5L5.5 5.5L5.5 4.5L6.5 4.5L6.5 5.5L6.5 6.5L6.5 7.4" pathLength="1"></path>
<circle class="loader-maze__goal" cx="6.5" cy="7.4" r="0.22"></circle>
</svg>CSS
@keyframes loader-maze-solve {
0% { stroke-dashoffset: 1; opacity: 1; }
70% { stroke-dashoffset: 0; opacity: 1; }
85% { stroke-dashoffset: 0; opacity: 1; }
100% { stroke-dashoffset: 0; opacity: 0; }
}
@keyframes loader-maze-goal {
0%, 66% { opacity: 0.35; transform: scale(1); }
72% { opacity: 1; transform: scale(1.8); }
85% { opacity: 1; transform: scale(1); }
100% { opacity: 0.35; }
}
.loader-maze { display: block; width: 96px; height: 96px; }
.loader-maze__walls { fill: none; stroke: light-dark(#6d7179, #7d8087); stroke-width: 0.1; stroke-linecap: square; }
.loader-maze__route {
fill: none;
stroke: light-dark(#373a40, #f1f2f3);
stroke-width: 0.16;
stroke-linecap: round;
stroke-linejoin: round;
stroke-dasharray: 1;
animation: loader-maze-solve 3s cubic-bezier(0.45, 0, 0.55, 1) infinite;
}
.loader-maze__goal {
fill: light-dark(#373a40, #f1f2f3);
transform-box: fill-box;
transform-origin: center;
animation: loader-maze-goal 3s ease infinite;
}
@media (prefers-reduced-motion: reduce) {
.loader-maze__route, .loader-maze__goal { animation: none; stroke-dashoffset: 0; }
}Goal: Create a "Maze" loader.
Visual behavior: A generated maze solves itself: the route draws from the entrance in the top corner to the exit in the bottom one, the goal flashes as it arrives, and the line fades before solving again.
Technique:
- A 7x7 perfect maze is carved with a seeded depth-first walk, so it is the same every render, and its closed sides become one SVG wall path.
- A breadth-first search from the first cell to the last finds the route, turned into a path through cell centres with pathLength 1.
- The route draws on a 3s loop (dashoffset 1 to 0, hold, fade); the goal dot pops as the line reaches it.
Accessibility: The root has role="status" and aria-label="Loading"; everything inside is decorative. Under prefers-reduced-motion the solved route is shown 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 "Maze" loader.
Visual behavior: A generated maze solves itself: the route draws from the entrance in the top corner to the exit in the bottom one, the goal flashes as it arrives, and the line fades before solving again.
Technique:
- A 7x7 perfect maze is carved with a seeded depth-first walk, so it is the same every render, and its closed sides become one SVG wall path.
- A breadth-first search from the first cell to the last finds the route, turned into a path through cell centres with pathLength 1.
- The route draws on a 3s loop (dashoffset 1 to 0, hold, fade); the goal dot pops as the line reaches it.
Accessibility: The root has role="status" and aria-label="Loading"; everything inside is decorative. Under prefers-reduced-motion the solved route is shown 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
A generated maze solves itself: the route draws from the entrance in the top corner to the exit in the bottom one, the goal flashes as it arrives, and the line fades before solving again.
- Dependencies
- None
- Difficulty
- Advanced
- Triggers
- continuous, loop, draw
- Techniques
- svg stroke, stroke dashoffset, keyframes
- Reduced motion
- Respected
- Theme
- Light and dark (follows your page's color-scheme)
The root has role="status" and aria-label="Loading"; everything inside is decorative. Under prefers-reduced-motion the solved route is shown still.