All effectsVisual styles

Grid Background

网格背景

A repeating pattern of horizontal and vertical lines adds a fine structure behind content.

Look at the repeated lines

Where to use it

Give a technical landing page, diagram, or workspace a subtle backdrop. Open up the grid spacing around dense text, and reserve a visible grid for areas that benefit from a drawing-board feel.

Practical example

A renovation planner places a faint square grid behind the sample floor plan. The grid makes the canvas feel like graph paper and leaves labels for room widths easy to scan.

Also called

  • Grid Pattern

AI prompt

Add a Grid Background behind [target section] using two perpendicular CSS gradients. Use consistent spacing and a low-contrast line color that adapts to the theme. Keep decorative lines behind the content and preserve legibility around text and buttons.

Example code

Save the standalone HTML as a file and open it in your browser. It uses the same code as the preview.

View HTML
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Grid Background</title>
  <style>
    :root {
      color-scheme: dark;
      --demo-bg: #171629;
      --demo-ink: #f8f5ff;
      --demo-accent: #b9a6ff;
      --demo-muted: #bfbbd3;
      font-family: system-ui, sans-serif;
      color: var(--demo-ink);
      background: var(--demo-bg);
    }

    *, *::before, *::after { box-sizing: border-box; }
    body { margin: 0; min-width: 0; }
    button, input { font: inherit; }

    .demo {
      display: grid;
      place-items: center;
      align-content: center;
      min-height: 100vh;
      padding: 14px;
      overflow: hidden;
      background: radial-gradient(ellipse at 50% 24%, #28233f, var(--demo-bg) 78%);
    }

    .demo-button {
      border: 1px solid #ffffff3d;
      border-radius: 7px;
      background: #ffffff12;
      color: var(--demo-ink);
      padding: 6px 11px;
      font-size: 12px;
      cursor: pointer;
    }

    :focus-visible {
      outline: 2px solid var(--demo-accent);
      outline-offset: 3px;
    }

    .grid-sample {
      --grid-line: #9680ce4d;
      position: relative;
      display: grid;
      align-content: center;
      justify-items: center;
      gap: 9px;
      width: min(100%, 276px);
      min-height: 120px;
      overflow: hidden;
      border: 1px solid #584b79;
      border-radius: 16px;
      background-color: #28223e;
      background-image:
        linear-gradient(90deg, var(--grid-line) 1px, transparent 1px),
        linear-gradient(var(--grid-line) 1px, transparent 1px);
      background-position: center;
      background-size: 17px 17px;
      color: #efe7ff;
      font-size: 14px;
      font-weight: 700;
    }
    .grid-sample > span { position: relative; background: #28223e; }
    .grid-sample > span:last-child { padding: 4px 8px; border-radius: 4px; }
    .grid-cross { width: 16px; height: 16px; border: 1px solid #cbb3ff; }
    .grid-cross::before, .grid-cross::after { position: absolute; inset: 50%; background: #cbb3ff; content: ''; }
    .grid-cross::before { width: 26px; height: 1px; transform: translateX(-50%); }
    .grid-cross::after { width: 1px; height: 26px; transform: translateY(-50%); }
  </style>
</head>
<body>
  <main class="demo">
    <div class="grid-sample">
      <span class="grid-cross" aria-hidden="true"></span>
      <span>Workspace</span>
    </div>
  </main>
</body>
</html>

Original example by UI Skills