Skip to content

shadcn.io is an independent project built on shadcn/ui

Pro

Flickering Grid Background for Svelte

A grid of small squares that flicker at random, a few bright at a time. For Svelte with Ark UI, when a page needs a quiet, living texture.

On this page10 sections
UI library: Ark UI

Flickering Grid draws a lattice of small squares. Each one holds a brightness, then eases to another at its own pace, so a few are bright at any moment over a faint resting grid, and slow patches of activity drift across. It's a GLSL scene on WebGL2 with no dependency, and every cell sits on whole device pixels, so the grid stays sharp and never shimmers. Its colors come from your theme: ink on a light surface, light on a dark one. The cells near the pointer light up.

Use it as a quiet texture behind a dashboard header, a status page or a developer hero. For a grid that holds still, use Dot Pattern; for chunky pixels that shimmer through a palette in waves, Pixels; for falling code instead of cells that blink in place, Matrix. With reduced motion it holds one still frame of the grid.

Playground
Flickering Grid Background, still
Customize

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

<script lang="ts">
import { FlickeringGrid } from "@/components/ui/flickering-grid";
</script>
<FlickeringGrid class="flex min-h-[32rem] flex-col items-center justify-center gap-4">
  <h1 class="text-5xl font-semibold">Every service, at a glance</h1>
  <p class="text-foreground/80">Uptime, latency and errors on one page.</p>
</FlickeringGrid>

Flickering Grid is a container: whatever you put inside sits on top of the cells, 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".

Presets

Flickerthe default lookTry it
<FlickeringGrid />
DotsTry it
<FlickeringGrid
  accentColor="#38bdf8"
  gap={8}
  intensity={1.5}
  shape="dot"
  size={4}
/>
Finethe default lookTry it
<FlickeringGrid gap={2} lit={0.5} scale={2} size={2} />
Plusthe default lookTry it
<FlickeringGrid
  flicker={0.6}
  gap={10}
  intensity={1.5}
  shape="plus"
  size={7}
/>
SparksTry it
<FlickeringGrid
  accentColor="#fb923c"
  contrast={2}
  flicker={1.6}
  intensity={2}
  lit={0.1}
  wave={0.2}
/>
StatusTry it
<FlickeringGrid
  accentColor="#34d399"
  color="var(--muted-foreground)"
  flicker={0.6}
  gap={3}
  intensity={1.6}
  lit={0.12}
  size={10}
  wave={0.2}
/>
Tidethe default lookTry it
<FlickeringGrid flicker={0.4} lit={0.5} scale={0.5} wave={1} />

Each preset is a set of props, so copy one and keep tuning. Flicker is the default. Status turns the grid into a wall of 10px tiles where about one in eight glows green, Plus swaps the squares for plus signs on a wider pitch, Sparks drops the resting grid and leaves a few orange cells, and Tide gathers the bright cells into large, slow patches.

Examples

Hero

The demo sets no props. A cell at its brightest covers about 40% of the surface in the foreground color, so a centered headline, a line of copy and two buttons read anywhere on the grid. The chip and the second button have a translucent ground of their own.

Preview width

Status lights

Larger tiles on a tight pitch (size={10}, gap={3}) in zinc on a dark surface, with accentColor="#34d399" for the bright ones. lit={0.12} keeps about one tile in eight bright, wave={0.2} scatters them evenly, flicker={0.6} slows the changes and intensity={1.6} lets them glow.

Preview width

In a card

shape="plus" draws each cell as a plus sign, here 7px wide on a 17px pitch (size={7}, gap={10}) with intensity={1.5}, since a plus has less ink than a square. fade="bottom" thins the grid out toward the copy at the bottom of the card.

Preview width

Customization

color is the cells and accentColor the color the brightest cells and the ones near the pointer turn. Both are CSS colors, so a theme variable works and follows a theme switch; the defaults are var(--foreground) and var(--primary). size and gap are in pixels and shape is square, dot or plus. lit sets the share of bright cells, contrast how far they stand out from the rest, and wave how much they gather into drifting patches.

The surface is the root's own background, bg-background by default. Give the root another (bg-zinc-950, bg-muted) and the cells are painted over it. fade masks an edge, opacity turns the whole effect down, and grain adds film grain.

<FlickeringGrid
  accentColor="var(--chart-2)"
  class="min-h-[32rem]"
  color="var(--muted-foreground)"
  fade="radial"
  gap={8}
  shape="dot"
/>

Performance

It's one WebGL2 canvas and one fragment shader, however many cells the box holds: a few hashes and two samples of simplex noise a cell, and nothing at all for the pixels between cells. It draws only while it's on screen and the tab is visible, shares one frame loop with every other background on the page, and lowers its own resolution if frames run long. quality sets the render scale yourself, and paused holds the frame.

Accessibility

The grid is decoration: it's hidden from assistive tech and lets every click through to your content. With reduced motion it draws one still frame and ignores the pointer. Nothing flashes: a cell eases to its next brightness and changes at most once a second by default, and under three times a second at flicker={3}.

At intensity={1} no cell covers more than 40% of a light surface or 42% of a dark one, the pointer's light included. On the default theme that measures 6.9:1 for foreground text over the darkest cell on white and 5.3:1 over the brightest cell on near-black. Above intensity={1} the brightest cells go under 4.5:1 on a dark surface, so keep body copy off the grid there or give it a ground of its own.

FAQ

How do I change the colors?

color sets the cells and accentColor the color the brightest ones turn, along with the cells near the pointer. Hex, oklch() and theme variables all work, and a variable follows your theme when it changes. The defaults are var(--foreground) and var(--primary), so on a theme with a colored primary the bright cells take your brand color with no props.

Does it work in light and dark mode?

Yes, with no prop to set. The default colors are theme variables, so the cells are dark ink on a light page and light on a dark one, and they switch with the theme. On a dark surface the scene lifts the dim cells a little, since faint light on black is harder to see than faint ink on white.

How do I change the size and spacing of the cells?

size is the side of a cell and gap the space between two, both in pixels: 4 and 6 by default. Both are rounded to whole device pixels, so every cell is drawn the same on any screen. size={2} with gap={2} is a fine texture; size={10} with gap={3} is a wall of tiles.

It flickers too fast or too slow. How do I adjust it?

flicker is the rate: at 1 each cell moves to a new brightness every 1 to 3 seconds, at 2 twice as often, and 0 holds the cells while the patches still drift. lit sets how many cells are bright at once, from 0 to 1. speed scales everything, the patches included. With reduced motion the grid holds one frame.

How do I put it behind the whole page?

Render it empty with className="fixed inset-0 -z-10". It still follows the pointer there, since it listens on the window. To put it behind one section, wrap that section's content in it and give it a height, such as min-h-svh.

Does it handle thousands of cells?

Yes. The cells aren't elements: one shader computes each pixel's cell and its brightness on the GPU, so 500 cells and 50,000 cost the same. It does nothing while it's off screen or the tab is hidden, and renders fewer pixels by itself if a device can't keep up. Touch never moves it, so scrolling on a phone isn't disturbed.

Does it work with Next.js and server components?

Yes. Import it into a server component and it renders its box and your content on the server; the canvas starts in the browser and fades in over the surface. It needs WebGL2, which every current browser has. Without it the box keeps its background, or the fallback you pass.

I'm coming from Magic UI's Flickering Grid. What changed?

squareSize is size, gridGap is gap, flickerChance is flicker and color is still color. maxOpacity is intensity, where 1 is a 40% cover. There are no width or height props: the container sets the size, and you put your content inside it.

API Reference

FlickeringGrid

data-slot="flickering-grid"

PropType
accentColor?string

The color the brightest cells and the cells near the pointer turn, any CSS color. The default follows your theme's primary color.

Default
"var(--primary)"
color?string

The color of the cells, any CSS color. The default follows your theme.

Default
"var(--foreground)"
contrast?number

How far apart the dim and the bright cells are: 0 is an even grid, 2 leaves only the bright ones.

Default
1
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"
fallback?string

What shows until the first frame and in browsers without WebGL2: a CSS background value that looks like the scene.

flicker?number

How often a cell changes its brightness: 1 is once every 1 to 3 seconds, 0 holds them.

Default
1
gap?number

The space between two cells, in pixels.

Default
6
grain?number

Film grain over the scene, from 0 to 1.

Default
0
intensity?number

How strongly the cells show over the surface. At 1 the brightest cell covers about 40% of it, which keeps copy on top readable.

Default
1
interactive?boolean

Whether the scene follows the pointer and answers a press. Touch never moves it, so scrolling a page on a phone isn't disturbed.

Default
true
lit?number

The share of cells that are bright at any moment, from 0 to 1.

Default
0.2
opacity?number

How strongly the scene shows over the surface, from 0 to 1.

Default
1
paused?boolean

Holds the current frame.

Default
false
quality?number

Render scale, from 0.25 to 1, of the screen's pixels (capped at 2×). Lower is cheaper and softer.

Default
1
radius?number

How far the pointer's light reaches, in pixels.

Default
120
scale?number

The size of the slow patches of activity that drift across the grid: higher packs more, smaller patches.

Default
1
seed?number

Another layout of the same look, from 0 to 20.

Default
0
shape?"square" | "dot" | "plus"

What a cell is: a square, a round dot or a plus sign.

Type
"square" | "dot" | "plus"
Default
"square"
size?number

The side of a cell, in pixels.

Default
4
speed?number

Animation speed: 1 is normal, 0 holds the frame.

Default
1
time?number

A fixed moment, in seconds: draws it and doesn't animate.

wave?number

How much the bright cells gather into drifting patches, from 0 (evenly scattered) to 1.

Default
0.6