CSS background pattern generator

Repeating backgrounds made from CSS alone — stripes, dots, grids, checks, triangles and zigzags — or draw your own pixel tile. Pick the colours and sizes, then copy the CSS or Tailwind classes.

Pattern
Colours
Code
.pattern {
  background-color: #eef2ff;
  background-image: repeating-linear-gradient(45deg, #6366f1 0 8px, transparent 8px 24px);
}

How the patterns are made

Every pattern except the pixel tile is drawn by CSS gradients with hard colour stops — a stop where one colour ends at the exact length where the next begins, so there is no fade. The pattern colour is painted over background-color; the rest of each gradient is transparent, so the background shows through. No image is downloaded.

Using it

CSS — add the .pattern class to any element with a size: a page section, a card, the whole body. Tailwind — the same declarations as arbitrary-property classes for Tailwind CSS v4 (spaces become _). Sizes are in pixels, so a pattern looks the same on a phone and a desktop; tiles start at the element's top-left corner. Put text on a pattern only when the two colours are close, or behind a solid panel — busy patterns make text hard to read. For soft colour blends instead of shapes, try the mesh gradient generator; for a wavy edge, the SVG wave generator.

How we test it

122 patterns across all 8 types are checked in Chrome 156. The CSS you copy is pasted on three boxes — wide, square and one with odd-numbered sides — and photographed: 76,167 pixels must be exactly the pattern colour or the background colour as worked out separately from the shape itself (where a stripe falls along the gradient line, how far a pixel is from a dot's centre, which square of the board it is in), with the largest difference 0/255. Pixels on an edge, where the browser smooths the line, are left out. The Tailwind classes, compiled by the real Tailwind CSS, and the preview must give exactly the same background as the CSS. Deliberately broken versions — a mirrored stripe angle, a dot radius read as a diameter, polka without its offset row, a grid with no columns, half-size checker squares, an unshifted zigzag, a pixel tile read sideways, Tailwind classes with spaces left in — must each be caught.

Questions

Why does the tile size have to be even?

Polka and zigzag move a copy of the tile by half its size. With an even size that is a whole number of pixels, so every edge lands on a pixel boundary and nothing blurs.

Can I use more than two colours?

Each pattern here uses one pattern colour over one background. To stack two patterns, put both background-image values in one list (comma-separated) with their sizes in the same order.

Is a CSS pattern faster than an image?

There is nothing to download, and the CSS is a few hundred bytes. The browser draws the gradients itself, which is cheap for a static background; avoid animating large patterned areas.

Can I use the patterns in commercial work?

Yes. They are built in your browser from the shapes, colours and sizes you choose; there is nothing to credit.