CSS Grid Background
A grid background made with two linear gradients and no images. Set the cell size, line width and colors live, then copy the CSS or the Tailwind classes.
.bg-grid {
--bg: #4b9c41;
--fg: #8fc188;
--size: 32px;
--line: 1px;
background-color: var(--bg);
background-image:
linear-gradient(var(--fg) var(--line), transparent var(--line)),
linear-gradient(90deg, var(--fg) var(--line), transparent var(--line));
background-size: var(--size) var(--size);
}<div class="
[--bg:#4b9c41]
[--fg:#8fc188]
[--size:32px]
[--line:1px]
[background-color:var(--bg)]
[background-image:linear-gradient(var(--fg)_var(--line),_transparent_var(--line)),_linear-gradient(90deg,_var(--fg)_var(--line),_transparent_var(--line))]
[background-size:var(--size)_var(--size)]
"></div><!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Grid — CSS background</title>
<style>
html, body { height: 100%; margin: 0; }
.bg-grid {
--bg: #4b9c41;
--fg: #8fc188;
--size: 32px;
--line: 1px;
background-color: var(--bg);
background-image:
linear-gradient(var(--fg) var(--line), transparent var(--line)),
linear-gradient(90deg, var(--fg) var(--line), transparent var(--line));
background-size: var(--size) var(--size);
}
</style>
</head>
<body class="bg-grid"></body>
</html>Save the pattern as an image, with your current colors and settings.
Grid in other colors
Click a color to try it in the preview above, then copy the code.
Browse by color: Red · Orange · Yellow · Green · Teal · Blue · Purple · Pink
How the grid pattern works
This grid is two linear-gradient() layers on the same tile. The first runs top to bottom and paints a line --line pixels tall at the top of each tile. The second is turned 90deg, so it paints a line down the left side. Repeat the tile and the lines meet to form a grid.
Each gradient goes straight from --fg to transparent at the same point, which gives a hard, crisp line instead of a fade.
--size sets the cell size and --line the line thickness. Whole-pixel values keep the lines sharp. Half pixels can blur on some screens.
A grid background suits developer tools, dashboards, landing-page heroes and anything with a technical or blueprint feel. For a dark grid, set --bg to a deep color and --fg a few shades lighter. The Tailwind tab outputs the same grid as arbitrary-property classes for Tailwind v4.