React Hexagon Background
Honeycomb hexagon grids that make interfaces feel engineered and precise. Build stunning React geometric background components with CSS clip-path, hover effects, responsive sizing, and TypeScript support for Next.js applications with shadcn/ui.
Powered by
Building geometric interfaces?
Join our Discord community for help from other developers.
Square grids are everywhere. Boring rectangles that say "I used CSS Grid and called it done." But what if your background could suggest precision engineering? Honeycomb efficiency? This React component creates perfect hexagon grids using CSS clip-path, with hover effects that make each cell feel interactive and intentional.
Engineered hexagon grids
Watch perfect geometric patterns respond to hover with smooth transitions:
Built for React applications with TypeScript and Next.js. Uses CSS clip-path with precise polygon coordinates to create perfect hexagons. The grid calculates optimal spacing automatically and responds to window resizing. Hover effects create subtle interactivity without distraction.
Installation
npx shadcn@latest add https://www.shadcn.io/registry/hexagon-background.json
npx shadcn@latest add https://www.shadcn.io/registry/hexagon-background.json
pnpm dlx shadcn@latest add https://www.shadcn.io/registry/hexagon-background.json
bunx shadcn@latest add https://www.shadcn.io/registry/hexagon-background.json
Usage
import { HexagonBackground } from "@/components/ui/hexagon-background";
export default function TechDashboard() {
return (
<div className="relative h-screen w-full">
<HexagonBackground
hexagonSize={75}
hexagonMargin={3}
className="absolute inset-0"
>
<div className="relative z-10 flex items-center justify-center h-full">
<div className="text-center">
<h1 className="text-4xl font-bold mb-4">Engineering Dashboard</h1>
<p className="text-xl text-muted-foreground">Precision by design</p>
</div>
</div>
</HexagonBackground>
</div>
);
}
Why most geometric backgrounds look amateur
Most developers use CSS transform: rotate on squares, creating jagged diamonds that look like placeholder graphics. Others use background-image SVGs that don't scale properly or respond to interactions. Some try drawing hexagons with borders and transforms—it's a mess of trigonometry that breaks on different screen sizes.
This React component uses CSS clip-path with precise polygon coordinates (50% 0%, 100% 25%, etc.) for mathematically perfect hexagons. Grid spacing uses optimal honeycomb ratios (0.8x vertical spacing) for natural tessellation. Window resize handlers recalculate the grid dynamically. Hover states use proper CSS transitions instead of JavaScript animation.
Features
- CSS clip-path hexagons with mathematically precise polygon coordinates
- Optimal honeycomb spacing using 0.8x vertical ratios for natural tessellation
- Responsive grid calculation automatically adjusting to viewport changes
- Smooth hover interactions with customizable CSS transition timing
- Dynamic sizing system supporting custom hexagon dimensions and margins
- Theme-aware styling with automatic dark/light mode color adaptation
- TypeScript definitions for all sizing and styling configuration options
- Performance optimized using CSS-only animations and efficient DOM structure
- shadcn/ui compatible with proper z-index layering and content overlay support
API Reference
HexagonBackground
Main component for CSS clip-path based hexagon grid backgrounds.
Prop | Type | Default | Description |
---|---|---|---|
hexagonSize | number | 75 | Size of each hexagon in pixels (minimum: 50) |
hexagonMargin | number | 3 | Spacing between hexagons in pixels |
hexagonProps | React.ComponentProps<'div'> | - | Additional props for individual hexagon elements |
children | React.ReactNode | - | Content to display over the hexagon grid |
className | string | - | Additional CSS classes for the container |
Hexagon Geometry
The component uses precise CSS clip-path coordinates for perfect hexagons:
/* Perfect hexagon using clip-path polygon */
clip-path: polygon(
50% 0%, /* Top point */
100% 25%, /* Top-right */
100% 75%, /* Bottom-right */
50% 100%, /* Bottom point */
0% 75%, /* Bottom-left */
0% 25% /* Top-left */
);
Grid Layout Mathematics
- Vertical spacing:
hexagonSize * 0.8
for optimal honeycomb tessellation - Horizontal spacing: Equal to
hexagonSize
for consistent alignment - Row offset: Alternating 50% margin for honeycomb stagger pattern
- Responsive calculations: Grid recomputes on window resize events
Common gotchas
Minimum size limitations: Hexagons smaller than 50px start losing their shape definition. The clip-path coordinates work best with larger sizes for crisp edges.
Z-index content layering: Your content needs relative z-10
or higher to appear above the hexagon grid. The hexagons use lower z-index values for proper background layering.
Performance with large grids: Each hexagon is a DOM element. Very large viewport sizes create hundreds of hexagons, which can impact performance on older devices.
Hover effects on touch devices: Mobile devices don't have true hover states. The hover effects won't trigger on touch, but the base hexagon appearance still looks great.
Grid alignment edge cases: On very narrow or very wide screens, the grid might not align perfectly at the edges. This is normal behavior for responsive geometric patterns.
CSS clip-path browser support: Modern browsers support clip-path well, but very old browsers (IE) won't show hexagons. They'll fall back to square shapes.
You might also like
Explore other geometric background components for React applications:
Grid Pattern
Clean SVG grid lines with masking and highlight effects
Background Boxes
Isometric 3D boxes with colorful hover interactions
Interactive Grid Pattern
Grid cells that respond to cursor hover movement
Dot Pattern
Minimalist dot grids with optional glow effects
Retro Grid
80s-style perspective grids with neon aesthetics
Noise
Organic texture patterns with customizable grain
Questions developers actually ask
React Grid Pattern Background
SVG grid lines that make interfaces feel structured and professional. Build clean React background components with CSS masks, highlighted cells, customizable spacing, and TypeScript support for Next.js applications with shadcn/ui.
React Interactive Grid Pattern
Grid backgrounds that light up on hover like Tron. Build responsive React grids with smooth hover effects, TypeScript support, and 60fps performance for Next.js dashboards with shadcn/ui integration.