Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Backgrounds

Pro

Boxes Background for React

An isometric grid of boxes behind your content where each box the pointer crosses lights up in a pastel colour and fades. For React with Base UI, when a portfolio or a playful landing page should invite people to play.

Framework

An isometric grid of boxes behind your content. Each box the pointer crosses lights up in a pastel colour and fades out over two seconds, so a quick swipe paints a trail across the page, and at rest the grid shows thin lines and small plus marks. The grid is one tilted SVG pattern and the trail reuses 48 boxes, so it stays light at any size, and nothing runs while the pointer rests.

Use it on a portfolio, a creative studio's page or anywhere people should want to play with the background. For the flat version in one colour, use Interactive Grid Pattern; for the same trail on a honeycomb, Hexagon. For a grid in perspective that scrolls toward a horizon, use Retro Grid; for a still grid, Grid Pattern. Cells that blink on their own are Flickering Grid, and zig-zag paper folds under a slow light are Origami.

Preview width

Installation

Part of Pro
Pro unlocks the code and one-line install of every Pro button and text effect, plus the MCP for your AI editor.
Have Pro already? Sign in to open it.Opens here as soon as you're Pro.

Usage

import { Boxes } from "@/components/ui/boxes";

Boxes is a container: give it a size and put your content inside. The grid sits behind the content, and the pointer lights boxes under the content too.

<Boxes className="flex min-h-[420px] items-center justify-center">
  <h1 className="text-5xl font-semibold">Paint the page as you go</h1>
</Boxes>

For a backdrop behind the whole page, leave it empty and fix it under everything else:

<Boxes className="fixed inset-0 -z-10" />

Demos

Theme colors

colors sets the colours lit boxes take, any CSS colours. Here your theme's five chart colours, var(--chart-1) to var(--chart-5), so the trail follows your brand.

Preview width

Duration

duration={1000} makes a quick one-second trail and cellSize={48} smaller boxes, in a card-sized box faded toward its bottom edge with fade="bottom". fade also takes top, none, and radial, the default, which fades the grid toward every edge.

Preview width

Accessibility

The grid is decoration: it's hidden from screen readers and never takes a click, so links and buttons on top keep working. Keep text on top in your foreground colour; a lit box is 90% opaque in light mode and 60% in dark, so dark text stays readable on the soft pastels and light text keeps at least 3:1 on the dark ones. Nothing loops. Each lit box rises over at least 100 ms instead of flashing on, and only where the pointer goes. With reduced motion the trail is off and the grid stays still. On touch screens a tap lights the box under the finger, and scrolling lights nothing.

FAQ

How big is the grid?

It's a repeating pattern, so it always fills its container, whatever its size. cellSize sets a box's width before the tilt, in pixels (default 64); its height is half that.

Which colours light up?

Nine pastels by default: sky, pink, green, yellow, red, purple, blue, indigo and violet. Pass colors with any CSS colours, theme variables like var(--chart-1) included. A box always gets the same colour, picked from its place in the grid, so neighbours differ and a box you come back to looks the same.

How does the isometric look work?

One transform, skewX(-48deg) skewY(14deg) scale(0.675), tilts both the grid's pattern and the plane the lit boxes sit in. To find the box under the pointer, its position is mapped back through the inverse of that transform.

How long does a box stay lit?

duration sets how long a box takes to fade, in milliseconds: 2000 by default, at least 1000 so each box rises gently. Shorter makes a tight trail, longer a long one.

Can I put content on top?

Yes, as children. Boxes light up under your content too, it stays clickable, and the edges fade out with fade.

Can I change the grid's colours?

lineColor sets the lines (your theme's --border by default), and the --boxes-plus CSS variable the plus marks (your muted foreground colour at 45%). Both follow light and dark.

API Reference

Boxes

<div> data-slot="boxes"

PropType
cellSize?number

A box's width before the tilt, in pixels; its height is half that. @default 64.

Default
64
colors?string[]

The colours lit boxes take, any CSS colours. Each box always gets the same one, picked from its place in the grid. Ark default: nine pastels (sky, pink, green, yellow, red, purple, blue, indigo and violet).

Default
PASTELS
duration?number

How long a lit box takes to fade out, in milliseconds. At least 1000, so a box always rises over 100 ms or more instead of flashing on.

Default
2000
fade?"none" | "radial" | "top" | "bottom"

Where the grid fades out: toward every edge from the centre (radial), toward the top, the bottom, or nowhere. It's a mask, so it fades into whatever is behind it.

Type
"none" | "radial" | "top" | "bottom"
Default
"radial"
lineColor?string

The grid lines' colour, any CSS colour. @default "var(--border)".

render?ReactElement | ((props: object, state: object) => ReactElement)

Replace the host element or compose it with another component.

Type
ReactElement | ((props: object, state: object) => ReactElement)
className?string

Merged with the part's classes.

CSS variableType
--boxes-durationstring

How long a lit box fades (2000ms, at least 1000ms).

--boxes-linestring

The grid lines' colour (var(--border)).

--boxes-plusstring

The plus marks' colour (45% of --muted-foreground).

All 100 backgrounds