Background

Hexagon Background

Responsive hexagon grid background with hover effects and customizable sizing. Perfect for React applications requiring geometric patterns with Next.js integration and TypeScript support.

Loading component...

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

Features

  • Responsive hexagon grid that automatically adjusts to viewport dimensions with window resize handling
  • CSS clip-path hexagons using precise polygon coordinates for perfect geometric shapes
  • Hover effects with smooth color transitions and customizable timing using CSS transitions
  • Dynamic grid calculation with optimized row and column sizing based on hexagon dimensions
  • Theme-aware styling with automatic light/dark mode support using neutral color palette
  • TypeScript support with complete interface definitions for all configuration props

Use Cases

This free open source React component works well for:

  • Technical websites - Engineering and tech company backgrounds in Next.js applications
  • Gaming interfaces - Sci-fi and futuristic UI designs using TypeScript and Tailwind CSS
  • Portfolio sites - Creative geometric backgrounds for showcasing technical work
  • Dashboard layouts - Subtle pattern backgrounds that don't interfere with content

API Reference

HexagonBackground

PropTypeDefaultDescription
hexagonSizenumber75Size of each hexagon in pixels (minimum value: 50)
hexagonMarginnumber3Spacing between hexagons in pixels
hexagonPropsReact.ComponentProps<'div'>-Additional props to apply to each hexagon element
childrenReact.ReactNode-Content to overlay on top of the hexagon background
classNamestring-CSS classes for container styling and theming

Grid Calculations

  • Row spacing - hexagonSize * 0.8 for proper vertical alignment
  • Column width - Equal to hexagonSize for consistent horizontal spacing
  • Offset pattern - Alternating rows with different left margins for honeycomb effect
  • Responsive sizing - Grid dimensions recalculate on window resize events

Hover Effects

  • Background transition - 1000ms duration with smooth color changes
  • Instant feedback - Hover states activate immediately (0ms duration)
  • Nested elements - Both before and after pseudo-elements respond to hover
  • Theme integration - Colors automatically adapt to light/dark mode preferences

Implementation Notes

  • Uses CSS custom properties for dynamic margin configuration
  • Clip-path creates perfect hexagon shapes with 6-point polygon coordinates
  • Window resize listener ensures grid stays responsive across all devices
  • Pseudo-elements create layered hexagon appearance with proper z-indexing
  • Component automatically cleans up event listeners on unmount
  • Supports all standard div HTML attributes and event handlers