Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Backgrounds

Pro

Life Background for React

Conway's Game of Life behind your content: gliders cross a faint dot lattice, blinkers pulse and dying cells fade. For React with Base UI, when an engineering page or a developer portfolio should feel computational rather than decorative.

Framework

Life runs Conway's Game of Life behind your content, eight generations a second. Gliders sail across a faint lattice of dots, blinkers pulse, still lifes settle, and a cell that dies fades out over two generations instead of vanishing. The board wraps at the edges, so patterns travel forever, and when it settles down one small patch is stirred up again.

Use it for engineering dashboards, developer tools and computer-science pages. For cells that flicker at random with no rules, use Flickering Grid; for the static lattice alone, Dot Pattern; for patterns that grow from chemistry rather than counting, Reaction Diffusion. It's a tiny canvas with one pixel per cell that CSS scales up and cuts into round dots, so a generation costs a fraction of a millisecond, nothing is drawn between generations, and it only runs while it's on screen.

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 { Life } from "@/components/ui/life";
<Life className="min-h-[480px]">
  <h1 className="text-5xl font-semibold">Ship faster</h1>
</Life>

Life is a container: give it a size, put your content inside, and the board sits behind it. The grid follows the box, one cell every cellSize pixels, so cells stay square at any size. For a background behind the whole page, pass className="fixed inset-0 -z-10" and no children.

Demos

Phosphor

color takes any CSS color; here a phosphor cyan on a bg-slate-950 section, the look of an old terminal. The lattice and the glow follow the color.

Preview width

Draw

With interactive, dragging with a mouse or a pen drops random clusters of live cells along the stroke, and the rules take it from there. Big cells (cellSize={24}) at half speed make it easy to follow. Touch never draws, so scrolling a page on a phone isn't disturbed.

Preview width

Accessibility

The board is decoration: it's hidden from assistive tech and never takes the pointer unless you turn on interactive, and even then it only listens on its own box. With reduced motion it runs 30 generations before the first paint and shows that board, still, with no drawing. Live cells are drawn at full strength, so put headings on a plate (such as bg-background/85) or keep copy short and in text-foreground. Nothing flashes: each generation changes scattered small dots, and a reseed stirs one small patch, never the whole board.

FAQ

What rules does it run?

Standard Conway's Game of Life, B3/S23: a dead cell with exactly three live neighbours is born, a live cell with two or three survives, and every other cell dies. The board wraps at the edges, so a glider that leaves on the right comes back on the left.

Why do new cells appear now and then?

Life settles into still lifes and blinkers within a minute or two. Every reseedInterval milliseconds (25 seconds at the default speed), or as soon as the board stops changing, one 12 × 12 patch is re-randomised and a glider is dropped. reseedInterval={0} turns it off and lets the board settle for good.

How do I change the cell size or the pace?

cellSize sets a cell in pixels (16 by default, at least 6), and the grid follows the box. speed scales the eight generations a second: 0.5 is calm, 2 is busy.

How do I change the color?

Pass color, any CSS color, or set --life-color on the component. By default it's your theme's primary color: solid dots on a light page and glowing ones on a dark page. The lattice is the same color at 18%.

Can visitors draw on it?

Yes, with interactive: dragging with a mouse or a pen drops random clusters of live cells along the stroke. It's off by default, and touch never draws.

Does it slow the page down?

No. A generation of a 1280 × 720 board (80 × 45 cells) takes well under a tenth of a millisecond, the canvas changes only eight times a second, and the loop stops when the board scrolls out of view.

Does it respect reduced motion?

Yes. It seeds the board, runs 30 generations before the first paint and shows that board without stepping, so you still see gliders and blocks, just not moving.

API Reference

Life

<div> data-slot="life"

PropType
cellSize?number

A cell's size in pixels, at least 6; the grid follows the box, so cells stay square. @default 16.

Default
16
color?string

The live cells' color, any CSS color; the faint lattice and the glow follow it. @default "var(--primary)".

interactive?boolean

Whether dragging with a mouse or pen draws live cells. @default false.

Default
false
reseedInterval?number

How often one small patch is stirred up to keep the board busy, in milliseconds at speed 1; it also happens when the board stops changing. 0 never stirs it, so the board may settle for good. Ark default: 25000.

Default
25_000
speed?number

Multiplies the pace of 8 generations a second. @default 1.

Default
1
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
--life-colorstring

The live cells' color (the theme's --primary).

All 100 backgrounds