CSS Graph Paper Background

Graph paper in pure CSS: bold major lines every five squares over fine dotted minor lines, from linear and radial gradients. Customize it live and copy it.

#880088
#b560b5
16px
.bg-graph-paper {
  --bg: #880088;
  --fg: #b560b5;
  --size: 16px;
  background-color: var(--bg);
  background-image:
    linear-gradient(var(--fg) 2px, transparent 2px),
    linear-gradient(90deg, var(--fg) 2px, transparent 2px),
    radial-gradient(circle at 0.5px 0.5px, color-mix(in srgb, var(--fg) 90%, transparent) 0.5px, transparent 0.8px),
    radial-gradient(circle at 0.5px 0.5px, color-mix(in srgb, var(--fg) 90%, transparent) 0.5px, transparent 0.8px);
  background-size:
    calc(var(--size) * 5) calc(var(--size) * 5),
    calc(var(--size) * 5) calc(var(--size) * 5),
    4px var(--size),
    var(--size) 4px;
}
<div class="
  [--bg:#880088]
  [--fg:#b560b5]
  [--size:16px]
  [background-color:var(--bg)]
  [background-image:linear-gradient(var(--fg)_2px,_transparent_2px),_linear-gradient(90deg,_var(--fg)_2px,_transparent_2px),_radial-gradient(circle_at_0.5px_0.5px,_color-mix(in_srgb,_var(--fg)_90%,_transparent)_0.5px,_transparent_0.8px),_radial-gradient(circle_at_0.5px_0.5px,_color-mix(in_srgb,_var(--fg)_90%,_transparent)_0.5px,_transparent_0.8px)]
  [background-size:calc(var(--size)_*_5)_calc(var(--size)_*_5),_calc(var(--size)_*_5)_calc(var(--size)_*_5),_4px_var(--size),_var(--size)_4px]
"></div>
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Graph Paper — CSS background</title>
  <style>
    html, body { height: 100%; margin: 0; }
    .bg-graph-paper {
      --bg: #880088;
      --fg: #b560b5;
      --size: 16px;
      background-color: var(--bg);
      background-image:
        linear-gradient(var(--fg) 2px, transparent 2px),
        linear-gradient(90deg, var(--fg) 2px, transparent 2px),
        radial-gradient(circle at 0.5px 0.5px, color-mix(in srgb, var(--fg) 90%, transparent) 0.5px, transparent 0.8px),
        radial-gradient(circle at 0.5px 0.5px, color-mix(in srgb, var(--fg) 90%, transparent) 0.5px, transparent 0.8px);
      background-size:
        calc(var(--size) * 5) calc(var(--size) * 5),
        calc(var(--size) * 5) calc(var(--size) * 5),
        4px var(--size),
        var(--size) 4px;
    }
  </style>
</head>
<body class="bg-graph-paper"></body>
</html>

Save the pattern as an image, with your current colors and settings.

Graph Paper 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 graph paper pattern works

Graph paper is two grids stacked on top of each other. The bottom two layers draw dotted minor lines every --size pixels. Each is a 1px radial-gradient() dot on a tile 4px long and one square wide, so the dots repeat every 4px along the line. The top two linear-gradient() layers draw solid 2px major lines on a tile five times larger, so every fifth line is bold.

The dots use color-mix(in srgb, var(--fg) 90%, transparent), a lighter version of the same color. That way you only set one line color, and the minor lines always match it.

Because the major tile is exactly five minor tiles, the bold lines always land on top of a minor line. --size moves in steps of 4px, so a dot always sits on every grid crossing.

Use it for engineering or math-themed pages, notebook-style apps, charts, and any layout that should feel measured or hand-drafted. The Tailwind tab gives the same layers as arbitrary-property classes for Tailwind v4.