Grid loader
Grid snake
A little light taking the scenic route. A single React component with its CSS built in and no dependencies. Install it with the shadcn CLI or copy the source.
Preview and installation
Run this command in any project set up with shadcn.
npx shadcn@latest add https://loadercn.vercel.app/r/grid-snake.jsonAdded the @loadercn registry? Use the short form:
npx shadcn@latest add @loadercn/grid-snakeThen add it to your interface:
import { GridSnake } from "@/components/ui/grid-snake"
<GridSnake size={48} speed={1.6} />Inherits text color. Accepts className, style, and a custom loading label. Respects reduced-motion preferences.
import type { CSSProperties, ComponentProps } from "react"
export type GridSnakeProps = ComponentProps<"span"> & {
size?: number
/** Duration of one cycle, in seconds. */
speed?: number
label?: string
}
export function GridSnake({
size = 40,
speed = 1.6,
label = "Loading",
className,
style,
...props
}: GridSnakeProps) {
return (
<span
role="status"
aria-label={label}
{...props}
className={["grid-snake-loader", className].filter(Boolean).join(" ")}
style={
{
width: size,
height: size,
"--loader-duration": `${Math.max(0.1, speed)}s`,
...style,
} as CSSProperties
}
>
<span aria-hidden="true" className="grid-snake-loader-grid">
{Array.from({ length: 9 }, (_, i) => {
const row = Math.floor(i / 3)
const col = i % 3
return (
<span
key={i}
style={{
animationDelay: `${((row % 2 === 0 ? row * 3 + col : row * 3 + 2 - col) * -0.13 * Math.max(0.1, speed)) / 1.6}s`,
}}
/>
)
})}
</span>
<style>{`
.grid-snake-loader { display: inline-flex; flex-shrink: 0; }
.grid-snake-loader-grid { display: grid; width: 100%; height: 100%; grid-template-columns: repeat(3, 1fr); gap: 14%; }
.grid-snake-loader-grid > span { background: currentColor; border-radius: 12%; animation: grid-snake-loader-motion var(--loader-duration) ease-in-out infinite; }
@keyframes grid-snake-loader-motion { 0%, 70%, 100% { opacity: .15; } 15%, 30% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .grid-snake-loader-grid > span { animation: none; opacity: .65; } }
`}</style>
</span>
)
}
Copy the complete file into your components directory. Styles are included.
When to use it
Good for longer waits where a bit of personality helps, like generating a report or processing an upload. The path gives the eye something to follow.
Props
Grid snake accepts size, speed, label, className, and style, like every loader in the collection. See the installation guide for the full reference.