Skip to content
Esc
↑↓navigate↵open⌘Jpreview
On this page

Astro Hexagon Pattern

A hexagon background that fills its container. The hover effect is optional.

Hover effect

Hexagon pattern

Installation

bunx --bun shadcn@latest add @gnostic/hexagon-pattern

Usage

The component is the box. Give it a height. The script fills that box with hexagon rows. Content in the slot sits above the field. Give text relative z-10 when the text must stay above the hexagons.

import { HexagonPattern } from "@/components/patterns/hexagon-pattern"
<HexagonPattern class="h-72" />

hoverEffect adds the hover color classes. Leave it unset for a static field.

<HexagonPattern hoverEffect class="h-72" />

hexagonSize is the width of one hexagon, in pixels. hexagonMargin is the gap. That gap is also the border thickness. hexagonColor paints each hexagon. gapColor paints the space between them. Leave gapColor unset to use bg-muted.

hoverFill and hoverStroke are the colors used while the pointer is over a hexagon. They apply only when hoverEffect is true.

Each preview has a Hover effect switch. The switch adds or removes the same classes as hoverEffect.

Examples

Large hexagons

hexagonSize sets the width. A larger size uses fewer cells.

Hover effect

Large hexagons

Small hexagons

A smaller size uses more cells. Lower hexagonMargin to keep the gap thin.

Hover effect

Small hexagons

Gradient overlay

A gradient layer covers part of the field. pointer-events-none lets the pointer reach the hexagons that remain visible.

Hover effect

Part of the field stays visible

Custom colors

gapColor, hexagonColor, hoverFill, and hoverStroke accept any CSS color. The two fields below use different sets of those colors.

Hover effect

Primary

Contrast

Without the hover effect

Leave hoverEffect unset. The switch at the top can still turn the classes on.

Hover effect

No hover effect

API Reference

HexagonPatternProps

PropType
hexagonSize?number

Width of one hexagon, in pixels. The height is 1.1 times this width.

Typenumber
Default75
hexagonMargin?number

Space between hexagons, in pixels. This space is also the border thickness.

Typenumber
Default3
hoverEffect?boolean

Change each hexagon color when the pointer is over it.

Typeboolean
Defaultfalse
hexagonColor?string

CSS color of each hexagon.

Typestring
Default"var(--background)"
gapColor?string

CSS color of the space between hexagons. Leave this unset to use the `bg-muted` class. A caller `bg-*` class can replace that class.

Typestring
hoverFill?string

CSS color of the hexagon fill while the pointer is over it. Used when `hoverEffect` is true.

Typestring
Default"var(--muted)"
hoverStroke?string

CSS color of the hexagon border while the pointer is over it. Used when `hoverEffect` is true.

Typestring
Default"color-mix(in oklch, var(--foreground) 18%, var(--background))"
hexagonClass?string

Extra classes for each hexagon. Use this to replace a fill or a hover color.

Typestring

See the registry source for the component source.