Skip to content
GitHub

Hexagon Pattern

A background hexagon pattern made with SVGs.

"use client";
import { HexagonPattern } from "@/components/backgrounds/pxl/hexagon-pattern";
import { cn } from "@/lib/utils";
export default function HexagonPatternDemo() {
return (
<HexagonPattern
hexagons={[
[1, 1],
[4, 4],
[2, 2],
[3, 4],
[5, 4],
[8, 2],
[6, 3],
[8, 5],
[10, 10],
]}
className={cn(
"mask-[radial-gradient(420px_circle_at_center,white,transparent)]",
"inset-0 skew-y-6",
)}
/>
);
}
pnpm dlx shadcn@latest add pxl-ui/registry/backgrounds/hexagon-pattern
import { HexagonPattern } from "@/components/backgrounds/pxl/hexagon-pattern"
<HexagonPattern />
"use client";
import { HexagonPattern } from "@/components/backgrounds/pxl/hexagon-pattern";
import { cn } from "@/lib/utils";
export default function HexagonPatternLinearGradient() {
return (
<HexagonPattern
radius={40}
x={-1}
y={-1}
className={cn(
"mask-[linear-gradient(to_bottom_right,white,transparent,transparent)]",
)}
/>
);
}
"use client"
import { HexagonPattern } from "@/components/backgrounds/pxl/hexagon-pattern"
export default function HexagonPatternDashed() {
return (
<HexagonPattern radius={40} x={-1} y={-1} strokeDasharray="4 2" />
)
}
"use client"
import { HexagonPattern } from "@/components/backgrounds/pxl/hexagon-pattern"
export default function HexagonPatternSpacing() {
return (
<HexagonPattern gap={20} radius={40} x={-1} y={-1} />
)
}

Use the variant prop to change the colors of the grid.

"use client";
import { HexagonPattern } from "@/components/backgrounds/pxl/hexagon-pattern";
import { cn } from "@/lib/utils";
export default function HexagonPatternVariants() {
return (
<div className="flex flex-wrap size-full items-center justify-center gap-2">
<div className="relative w-max h-32 aspect-video pixel-rounded pixel-size-lg">
<HexagonPattern
variant="muted"
hexagons={[
[1, 1],
[4, 4],
[2, 2],
[3, 4],
[5, 4],
[8, 2],
[6, 3],
[8, 5],
[10, 10],
]}
className={cn(
"mask-[radial-gradient(420px_circle_at_center,white,transparent)]",
"inset-0 skew-y-6",
)}
/>
</div>
<div className="relative w-max h-32 aspect-video pixel-rounded pixel-size-lg">
<HexagonPattern
variant="primary"
hexagons={[
[1, 1],
[4, 4],
[2, 2],
[3, 4],
[5, 4],
[8, 2],
[6, 3],
[8, 5],
[10, 10],
]}
className={cn(
"mask-[radial-gradient(420px_circle_at_center,white,transparent)]",
"inset-0 skew-y-6",
)}
/>
</div>
<div className="relative w-max h-32 aspect-video pixel-rounded pixel-size-lg">
<HexagonPattern
variant="info"
hexagons={[
[1, 1],
[4, 4],
[2, 2],
[3, 4],
[5, 4],
[8, 2],
[6, 3],
[8, 5],
[10, 10],
]}
className={cn(
"mask-[radial-gradient(420px_circle_at_center,white,transparent)]",
"inset-0 skew-y-6",
)}
/>
</div>
<div className="relative w-max h-32 aspect-video pixel-rounded pixel-size-lg">
<HexagonPattern
variant="success"
hexagons={[
[1, 1],
[4, 4],
[2, 2],
[3, 4],
[5, 4],
[8, 2],
[6, 3],
[8, 5],
[10, 10],
]}
className={cn(
"mask-[radial-gradient(420px_circle_at_center,white,transparent)]",
"inset-0 skew-y-6",
)}
/>
</div>
<div className="relative w-max h-32 aspect-video pixel-rounded pixel-size-lg">
<HexagonPattern
variant="warning"
hexagons={[
[1, 1],
[4, 4],
[2, 2],
[3, 4],
[5, 4],
[8, 2],
[6, 3],
[8, 5],
[10, 10],
]}
className={cn(
"mask-[radial-gradient(420px_circle_at_center,white,transparent)]",
"inset-0 skew-y-6",
)}
/>
</div>
<div className="relative w-max h-32 aspect-video pixel-rounded pixel-size-lg">
<HexagonPattern
variant="danger"
hexagons={[
[1, 1],
[4, 4],
[2, 2],
[3, 4],
[5, 4],
[8, 2],
[6, 3],
[8, 5],
[10, 10],
]}
className={cn(
"mask-[radial-gradient(420px_circle_at_center,white,transparent)]",
"inset-0 skew-y-6",
)}
/>
</div>
</div>
);
}
Prop Type Default Description
variant "default" | "primary" | "secondary" | "muted" | "success" | "warning" | "danger" "default" Colors of the grids
radius number 40 Radius from center to vertex for each hexagon
gap number 0 Extra spacing between adjacent hexagons (pixels)
x number -1 X offset of the pattern origin
y number -1 Y offset of the pattern origin
direction "horizontal" | "vertical" "horizontal" horizontal — flat-top honeycomb; vertical — pointy-top honeycomb
hexagons Array<[col, row]> Grid coordinates of highlighted (filled) hexagons
strokeDasharray string "0" SVG stroke-dasharray for outline hexagons in the repeating pattern
className string Additional classes on the root SVG (for example Tailwind color utilities)