How do I make a polka dot background in CSS?
Use a radial-gradient as the background-image and set background-size to the spacing you want between dots. The gradient draws one dot per tile, and the browser repeats the tile across the element.
A CSS background pattern is a repeating texture drawn with gradients, so it needs no image file. Pick dots, stripes, a grid or a checkerboard below and copy the ready background-image CSS or Tailwind class.
Pick a pattern, set the colours, size and line thickness, and copy the CSS: every pattern is built from CSS gradients, so there is no image to download and it scales sharply on any screen.
Live preview
.pattern {
background-color: #ffffff;
background-image: radial-gradient(rgb(99, 102, 241) 4px, transparent 4.5px);
background-size: 24px 24px;
}bg-[radial-gradient(rgb(99,_102,_241)_4px,_transparent_4.5px)]A pattern is a small tile drawn with a gradient and repeated by the browser. Dots use a radial-gradient that paints one circle per tile, while stripes use a repeating-linear-gradient that redraws the same band at a fixed angle. A grid is two linear-gradient layers, one for the vertical lines and one for the horizontal lines.
The background-size property sets the size of that tile, so it controls the spacing between dots or the width of each stripe. Change the colour stops to set the line thickness, and layer several gradients with comma-separated background-image values when a pattern needs more than one shape.
| Pattern | CSS function | Best for |
|---|---|---|
| Dots | radial-gradient | Subtle section backgrounds |
| Stripes | repeating-linear-gradient | Banners and progress bars |
| Grid | Two linear-gradients | Canvas and blueprint looks |
| Checkerboard | conic-gradient | Transparency backgrounds |
Use a radial-gradient as the background-image and set background-size to the spacing you want between dots. The gradient draws one dot per tile, and the browser repeats the tile across the element.
Use repeating-linear-gradient with two colour stops and an angle. The repeating function redraws the stripe every time the pattern reaches the end of the stop list, so you only set the stripe width once.
For simple dots, stripes, grids and checkerboards, yes. A CSS pattern is a few lines of code, needs no image request, stays sharp on every screen and can be recoloured with a variable instead of a new file.
Keep the pattern low contrast against the background and put the text on a solid or semi-transparent panel. Check the text and panel colours with a contrast checker rather than the pattern itself.
Related: style the scrollbar to match.