shadcn.io is an independent project built on shadcn/ui
Grid Pattern Background for Solid
A square grid with dashes, heavier lines and cells that light up, in CSS. For Solid with Ark UI, when a hero needs quiet structure.
On this page10 sections
A square grid of thin lines sits behind your content, like graph paper. It's drawn in CSS, with no canvas and no WebGL: the lines are hard-edged gradients placed on whole pixels, so they stay sharp at any size and screen ratio, and a cell is centered in the box so the grid crops the same on both sides. A few cells light up and fade in turn, every nth line can be heavier, and the lines near the pointer take the accent color. The colors are theme tokens, so it follows light and dark.
Use it behind a hero, a pricing section, a card header or an editor canvas, where a page needs structure and very little motion. For dots in place of lines, use Dot Pattern; for cells that fill under the pointer and leave a trail, Interactive Grid Pattern; for a grid in perspective running to a horizon, Retro Grid. With reduced motion the lit cells hold still.


Installation
Usage
import { GridPattern } from "@/components/ui/grid-pattern";<GridPattern
class="flex min-h-[32rem] flex-col items-center justify-center"
fade="bottom"
>
<h1 class="text-5xl font-semibold">Every screen lines up</h1>
</GridPattern>Grid Pattern is a container: whatever you put inside sits on top of the grid, in normal flow. It fills its own box, so give it a height or content. For a backdrop behind the whole page, render it empty with className="fixed inset-0 -z-10". There the lit cells still run, but the light doesn't follow the pointer: the page's content is on top and takes the pointer first.
Presets
<GridPattern /><GridPattern
accentColor="#3b82f6"
color="rgb(59 130 246 / 0.3)"
majorEvery={5}
size={20}
squares={6}
/><GridPattern dashed fade="bottom" size={32} squares={3} /><GridPattern majorEvery={4} size={16} squares={0} /><GridPattern
accentColor="#8b5cf6"
fade="bottom"
size={56}
speed={1.5}
squares={20}
/><GridPattern
accentColor="#22c55e"
color="rgb(34 197 94 / 0.25)"
dashed
size={24}
squares={10}
/><GridPattern
color="color-mix(in oklab, var(--foreground) 10%, transparent)"
lineWidth={2}
size={72}
squares={5}
/>Each preset is a set of props, so copy one and keep tuning. Grid is the default. Blueprint draws a heavier line every five cells in blue, Graph does the same in the theme's own colors on a 16-pixel cell, and Mosaic lights twenty large cells in violet over a grid that fades toward the bottom.
Examples
Hero
The grid covers the top of the box and fade="bottom" thins it out under the buttons, with majorEvery={4} for a heavier line every four cells. The headline and the line under it use the foreground color; the chip and the second button have a translucent ground of their own.
Blueprint
White lines on a blue surface. The surface is the root's own class (bg-blue-800), color is white at 16%, majorEvery={5} on a 20-pixel cell gives the blocks of five, and accentColor="#ffffff" makes the lit cells, the heavier lines and the pointer's light white.
In a card
dashed on a 24-pixel cell in a max-w-sm card, with fade="bottom" so the lines are gone before they reach the copy. squares={4} keeps the lit cells few in a small box.
Customization
Every color is a CSS color, so a theme variable works and follows a theme switch. color is the lines, var(--border) by default, and accentColor is the lit cells and the pointer's light, var(--foreground) by default. The heavier lines and the dashes are the line color mixed a step toward the accent, so one accent tints the whole grid. Each prop also has a CSS variable (--grid-pattern-size, --grid-pattern-color, --grid-pattern-accent), so a stylesheet or a media query can set it.
The grid is transparent: it draws on whatever is behind it, so a class on the root (bg-muted, bg-slate-950) is the surface. On a surface darker than your theme's, pass colors that read on it, or add the dark class so the tokens flip. fade masks an edge, size and lineWidth are in pixels, and the lines stay on whole pixels at every value.
<GridPattern
accentColor="var(--chart-2)"
class="min-h-[32rem]"
color="color-mix(in oklab, var(--chart-2) 25%, transparent)"
fade="radial"
majorEvery={4}
/>Performance
It's CSS: no canvas, no WebGL and no frame loop. The lines are four gradient layers on one element, painted once and again only when the box changes size. Each lit cell is one small element whose opacity and position the compositor animates, 24 at most, and the browser skips them while the grid is off screen (content-visibility: auto). The pointer's light is one element moved by translate under a mask of the lines; a pointer move writes two CSS variables and no Solid state. With squares={0} and interactive={false} it's a still picture that costs nothing after the first paint.
Accessibility
The grid is decoration: it's hidden from assistive tech and lets every click through to your content. With reduced motion the lit cells hold still where they are, and the light follows the pointer without gliding. Nothing flashes: a cell takes about three seconds to fade in and four to fade out.
Keep copy in the foreground color (text-foreground). The default lines are the theme's border color, and a lit cell is the foreground at 12% at its brightest. Text in the foreground color on a lit cell measures 15.2:1 in light and 14.3:1 in dark, and 9.4:1 at 80% opacity (text-foreground/80). With a strong color or accentColor of your own, check the copy on a lit cell again.
FAQ
How do I change the colors?
color sets the lines and accentColor sets the lit cells and the light under the pointer. Both take any CSS color: hex, oklch(), color-mix() or a theme variable such as var(--primary), which follows your theme when it changes. A translucent line color, such as rgb(59 130 246 / 0.3), sits on any surface.
Does it follow dark mode?
Yes, with no prop to set: the defaults are var(--border) and var(--foreground), so the grid changes with the theme. If you put it on a fixed dark surface inside a light page, such as bg-slate-950, either pass colors that read on it or add the dark class to the component so the tokens resolve to their dark values.
How do I put it behind the whole page?
Render it empty with className="fixed inset-0 -z-10". The lit cells keep running, but the light can't follow the pointer there, because the page's content sits on top and receives the pointer. To keep the light, wrap a section's content in the component and give it a height, such as min-h-svh.
Does it use a canvas or WebGL?
No. The lines are CSS gradients, the lit cells are small elements animated by the compositor, and the light is one element moved with translate. Nothing runs each frame in JavaScript, and a still grid (squares={0}, interactive={false}) costs nothing after it's painted. The only script is the pointer handler, which writes two CSS variables.
Does it work with Next.js and server components?
Yes. Import it into a server component: the grid and the lit cells are in the HTML the server sends, so they show at first paint, before any script loads. The lit cells are placed by a fixed sequence, not at random, so the server and the browser render the same markup. The file is a client component only for the pointer handler.
What happens with reduced motion and on touch screens?
With reduced motion the lit cells freeze where they are, each at its own brightness, and the light moves to the pointer without gliding. On a touch screen the light never shows, so a finger scrolling the page doesn't drag it around; the lit cells run as usual.
How do I get a blueprint or graph paper look?
Set majorEvery: every nth line is drawn heavier, so majorEvery={5} with size={20} gives blocks of five small cells. For a blueprint, add a blue or white color and the same hue as accentColor, as the Blueprint preset does. The heavier lines stay centered in the box when the step is an odd number.
Can I choose which cells light up?
You choose how many take turns, with squares (0 to 24), and a little over half of them show at any moment; seed gives another layout. Each lit cell fades in, fades out, then moves a few cells on, so no cell stays lit and the layout doesn't depend on the box's size. speed sets how fast they come and go, and squares={0} turns them off.
API Reference
GridPattern
<div> data-slot="grid-pattern"
accentColor?string
The color of the lit cells and of the light under the pointer, any CSS color. A theme variable follows your theme.
- Default
"var(--foreground)"
color?string
The lines' color, any CSS color. A translucent one sits on any surface.
- Default
"var(--border)"
dashed?boolean
Draws the lines as dashes, four to a cell, with one across each crossing.
- Default
false
fade?"none" | "radial" | "top" | "bottom" | "left" | "right"
Which edges fade out to the surface: radial keeps the middle, the
others name the side that fades.
- Type
"none" | "radial" | "top" | "bottom" | "left" | "right"- Default
"none"
interactive?boolean
Whether the lines near the pointer light up. Touch never lights them.
- Default
true
lineWidth?number
The lines' width, in pixels.
- Default
1
majorEvery?number
Draws every nth line heavier, as on graph paper: 5 gives blocks of five cells. 0 keeps every line the same.
- Default
0
radius?number
How far the light under the pointer reaches, in pixels.
- Default
180
seed?number
Another layout of the lit cells, a whole number.
- Default
0
size?number
The side of one cell, in pixels.
- Default
40
speed?number
How fast the lit cells come and go: 1 is normal, 0 holds them.
- Default
1
squares?number
How many cells take turns lighting up, from 0 to 24; a little over half of them show at a time. Each fades in and out, then moves a few cells on.
- Default
8
class?string
Merged with the part's classes.
data-dashed?string
Present when dashed is set.
data-fade?string
Mirrors fade.
data-major?string--grid-pattern-accentstring
The lit cells' and the light's color (var(--foreground)).
--grid-pattern-colorstring
The lines' color (var(--border)).
--grid-pattern-line-widthstring
The lines' width (1px).
--grid-pattern-radiusstring
How far the pointer's light reaches (180px).
--grid-pattern-sizestring
The side of one cell (40px).
--grid-pattern-speedstring
How fast the lit cells come and go (1).











