CSS Background Patterns Made with Pure Gradients

•

You don’t need image files to put a pattern behind your content. CSS gradients can draw stripes, dots, grids and checkerboards directly in the browser. A CSS background pattern built this way is tiny, sharp on every screen and easy to recolor with a single variable. This guide walks through the most useful patterns with code you can copy.

Tiles showing striped, dotted, grid and checkerboard background patterns side by side

How CSS patterns work

Every pattern below relies on two ideas.

  1. A gradient draws one tile. Gradients can have hard edges when two color stops share the same position. That turns a smooth fade into a solid shape.
  2. background-size repeats the tile. Backgrounds repeat by default, so a small tile becomes a full pattern.

Here’s the simplest example, a set of vertical stripes:

.stripes {
  background-image: linear-gradient(90deg, #4f46e5 50%, #eef2ff 50%);
  background-size: 40px 100%;
}

The gradient fills the first half of each 40px tile with indigo and the second half with pale blue. Our guide to the CSS linear gradient explains hard stops and color hints in more detail.

Stripes

Diagonal stripes

repeating-linear-gradient() is the cleanest way to draw diagonal stripes, because it repeats along the gradient line and doesn’t need background-size.

.diagonal {
  background-image: repeating-linear-gradient(
    45deg,
    #f97316 0 12px,
    #fff7ed 12px 24px
  );
}

Change the angle for a different slope, and change the two lengths to make the stripes thicker or thinner.

Pinstripes

Very thin lines on a light background make a subtle pattern for page sections and cards.

.pinstripe {
  background-image: repeating-linear-gradient(
    90deg,
    rgb(0 0 0 / 0.06) 0 1px,
    transparent 1px 24px
  );
}

Polka dots

Dots come from radial-gradient(). Each tile draws one circle, and background-size spaces them out.

.dots {
  background-color: #fdf2f8;
  background-image: radial-gradient(#db2777 20%, transparent 21%);
  background-size: 24px 24px;
}

The 1% gap between the two stops gives the edge a slight anti-aliasing, so the dots stay round instead of jagged.

For a staggered layout, add a second layer offset by half a tile:

.dots-staggered {
  background-color: #fdf2f8;
  background-image:
    radial-gradient(#db2777 20%, transparent 21%),
    radial-gradient(#db2777 20%, transparent 21%);
  background-size: 24px 24px;
  background-position: 0 0, 12px 12px;
}

Want different shapes or soft glowing dots? Our CSS radial gradient guide covers ellipses, sizes and positions.

CSS grid pattern

A grid pattern uses two linear gradients: one for horizontal lines and one for vertical lines.

.grid {
  --line: rgb(15 23 42 / 0.08);
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 32px 32px;
}

This is the classic graph paper look used behind dashboards, landing pages and design tool canvases. For a stronger major grid every four squares, add two more layers with a larger size and slightly darker lines.

Monitor displaying a web page with a subtle dotted background behind content cards

Checkerboard

A checkerboard is easiest with a conic gradient, which paints the four quarters of each tile around its center.

.checker {
  background-image: repeating-conic-gradient(#1e293b 0 25%, #f8fafc 0 50%);
  background-size: 40px 40px;
}

The 0 in the second stop means “start where the previous color ended”, which keeps the edges hard. The CSS conic gradient guide explains how starting angles and stops work around the circle.

Zigzag

Zigzags combine two diagonal gradients per tile.

.zigzag {
  background-color: #ecfeff;
  background-image:
    linear-gradient(135deg, #0891b2 25%, transparent 25%),
    linear-gradient(225deg, #0891b2 25%, transparent 25%);
  background-size: 40px 40px;
  background-position: 0 0, 0 0;
}

Small changes to the percentages and positions turn this into triangles, chevrons or a sawtooth edge. It’s worth experimenting in the browser’s dev tools.

Making patterns easy to reuse

Custom properties turn any pattern into a small design system component.

.pattern {
  --size: 24px;
  --fg: #6366f1;
  --bg: #eef2ff;
  background-color: var(--bg);
  background-image: radial-gradient(var(--fg) 20%, transparent 21%);
  background-size: var(--size) var(--size);
}

Change three variables and the same class serves a light section, a dark footer and a brand-colored banner.

Layering patterns over gradients

Because background-image accepts several layers, you can put a pattern on top of a color fade or a soft mesh. The first layer listed sits on top.

.hero {
  background-image:
    radial-gradient(rgb(255 255 255 / 0.15) 1px, transparent 1px),
    linear-gradient(135deg, #312e81, #7c3aed);
  background-size: 20px 20px, 100% 100%;
}

For richer, painterly backgrounds behind a pattern, see our guide to the CSS mesh gradient. If you work in Tailwind, the same code fits inside an arbitrary bg-[...] class, and our Tailwind gradient guide shows how.

Readability and accessibility

Patterns sit behind content, so they should never compete with it.

  • Keep contrast low. A pattern at 5 to 10 percent opacity reads as texture. At full strength it becomes noise.
  • Avoid busy patterns behind text. Put text on a solid card or panel above the pattern.
  • Watch fine stripes. High-contrast thin stripes can shimmer on some screens and bother people sensitive to visual patterns.
  • Respect dark mode. Swap the pattern colors with a media query or theme variables rather than inverting everything.

Performance

Gradient patterns are lightweight: no network request and no image decoding. Very large numbers of layers on huge elements can cost some paint time on low-end phones, especially if you animate background-position. For static backgrounds, they’re usually cheaper than image tiles.

Using a CSS background pattern generator

A CSS pattern generator speeds up exploration. You tweak colors, size and spacing visually, then copy the code. Read the output before you paste it into production. Generators sometimes add vendor prefixes you no longer need or use more layers than the pattern requires.

FAQ

How do I make a pattern background in CSS without images?

Use gradients for the shapes and background-size to repeat them. Linear gradients make stripes and grids, radial gradients make dots and conic gradients make checkerboards.

How do I make a grid pattern in CSS?

Layer two 1px linear gradients, one horizontal and one rotated 90 degrees, and set background-size to the cell size.

Can I animate a CSS background pattern?

Yes. Animating background-position makes stripes or dots move. Keep it subtle and respect the reduced motion setting.

Are CSS patterns supported in all browsers?

Linear, radial and conic gradients work in all current major browsers.