CSS Two Color Background Gradient Trick

A two color background in pure CSS: a sharp split between two colors, horizontal, vertical or diagonal. Set the angle and split point live, then copy it.

#223b8c
#167364
135deg
50%
.bg-two-color {
  --bg: #167364;
  --c1: #223b8c;
  --angle: 135deg;
  --split: 50%;
  background-color: var(--bg);
  background-image: linear-gradient(var(--angle), var(--c1) var(--split), var(--bg) calc(var(--split) + 1px));
}
<div class="
  [--bg:#167364]
  [--c1:#223b8c]
  [--angle:135deg]
  [--split:50%]
  [background-color:var(--bg)]
  [background-image:linear-gradient(var(--angle),_var(--c1)_var(--split),_var(--bg)_calc(var(--split)_+_1px))]
"></div>
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Two Color — CSS background</title>
  <style>
    html, body { height: 100%; margin: 0; }
    .bg-two-color {
      --bg: #167364;
      --c1: #223b8c;
      --angle: 135deg;
      --split: 50%;
      background-color: var(--bg);
      background-image: linear-gradient(var(--angle), var(--c1) var(--split), var(--bg) calc(var(--split) + 1px));
    }
  </style>
</head>
<body class="bg-two-color"></body>
</html>

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

How this two color works

A two color background is a linear-gradient() with no blend. The first color runs up to --split, and the second color starts 1px later. With almost no room to fade, the change is a crisp line. The extra pixel smooths the edge on diagonals, which would look jagged with a perfectly hard stop.

--angle sets the direction of the split:

  • 90deg: a vertical split, first color on the left and second on the right.
  • 180deg: a horizontal split, first color on top.
  • 135deg (default): a diagonal split from the top left.

--split moves the line. 50% splits the element evenly. 30% or 70% gives an off-center two-tone, which works well behind a hero with text on one side and an image on the other.

Use it for split hero sections, pricing tables that compare two plans, before-and-after layouts and bold section backgrounds.

All CSS background gradients →