By · Updated

CSS Pattern Generator

Checkerboard, Zigzag and Crosshatch Backgrounds Built Purely From CSS Gradients

No ratings yet

OneTask is free, with no sign-up, and built by one person.
If this tool saved you time, a coffee helps keep new ones coming.

How the CSS Pattern Generator works

This CSS pattern generator makes stripes, grids and dots from gradients alone. Every pattern here is nothing but background-image gradients tiled with background-size. Pick a pattern, set the tile size and line weight, choose two colours, and copy a rule that weighs a few hundred bytes, scales to any resolution and recolours with a single edit — no PNG, no SVG, no request.

CSS pattern generator: gradients that tile

A CSS gradient is an image, and like any background image it repeats. Combine a gradient that draws a hard-edged shape — a line, a dot, a triangle — with a background-size that sets the tile, and the browser tiles it across the element. Stack two or more gradients and offset them with background-position, and you get grids, checkerboards and zigzags. That is the whole technique; the six patterns in this tool are the ones that cover most real-world needs.

Stripes use repeating-linear-gradient, which repeats its colour stops without needing a background-size. The stops fg 0 4px, transparent 4px 24px mean a 4px stripe then a 20px gap, and the angle rotates the whole thing. Diagonal stripes at 45° are the classic "under construction" and progress-bar look; 90° gives vertical pinstripes.

Grid stacks a horizontal and a vertical linear gradient, each drawing a single line at the top or left of the tile. It is the standard graph-paper and blueprint background, and at a 1px thickness with a low-contrast colour it makes a subtle texture for dashboards.

Dots use a radial-gradient that is solid to a small radius and transparent beyond. The half-pixel overlap between the solid and transparent stops is deliberate: it anti-aliases the edge so the dots look round rather than jagged.

Checks are two identical 45° gradients, each drawing two opposite quarter-triangles of a tile, with the second offset by half the tile so the triangles complete each other into squares. The tile size sets the size of a pair of squares.

Zigzag is four diagonal gradients, one from each corner, positioned so the triangles align into a continuous chevron. Crosshatch is two repeating stripe gradients at +45° and −45°.

Why gradients rather than an image. A gradient background costs no network request, is resolution independent so it stays crisp on high-density screens, and can be recoloured or resized from CSS — including inside a prefers-color-scheme: dark block or on hover. An SVG data URI does all of that too, and is the better choice for shapes gradients cannot draw, such as hexagons or waves; the SVG data URI tool on this site covers that path.

Rendering notes. Hard colour stops at the same position produce a sharp edge, but on non-axis angles browsers anti-alias them slightly differently, so diagonal stripes may show faint seams at tile boundaries in some engines. Keeping the tile size an even number and the stripe thickness a whole pixel reduces it. Repeating gradients over very large areas are cheap to paint; stacking four gradients, as zigzag does, is still far lighter than a decoded image.

Using the output. The rule applies to any block element. For a full-page texture put it on body; for a card header, on the header. Combine it with a semi-transparent overlay gradient in the same background-image list to fade the pattern out towards one edge.

FAQ

Why do my diagonal stripes have faint seams?

Because the browser anti-aliases each tile edge independently and the seams do not always line up perfectly at non-right angles. Use an even tile size and whole-pixel thickness, or switch to repeating-linear-gradient for stripes, which draws continuously without tiles and avoids the problem.

Can I animate the pattern?

Yes. Animating background-position scrolls it — a moving diagonal stripe is the classic progress bar. Animating the colours or sizes is possible with custom properties registered through @property, but plain gradient values do not interpolate, so without that they snap rather than tween.

How is this different from an SVG pattern?

Gradients can only draw shapes made of straight edges and circles, so stripes, grids, dots and checks are their sweet spot. SVG patterns can draw any path — hexagons, waves, icons — at the cost of a slightly longer data URI. Both are resolution independent and need no request.

Does the pattern colour need to be opaque?

No. A semi-transparent pattern colour over the background gives a softer texture and lets the same rule work over different backgrounds. Set the pattern colour to something like rgba(255,255,255,.08) by hand in the copied code for a subtle light-on-dark texture.

Why does the checkerboard show at half the tile size?

The tile size sets one pair of squares — a light and a dark — because the checker is built from two offset gradients that each draw half the pattern. For 20px squares, set the tile size to 40px.

See also: all Shadows & Motion tools, Layout & Spacing, Shapes & SVG, UI Components, Forms & Inputs, Colour.

Related tools