CSS 3D Cubes Background

A 3D cubes pattern in pure CSS: stacked isometric cubes with a light top and two shaded sides, from three conic gradients. Set the cube size and colors live.

#880088
#b560b5
60px
.bg-cubes {
  --bg: #880088;
  --fg: #b560b5;
  --size: 60px;
  background-color: var(--bg);
  background-image:
    conic-gradient(from 120deg at 50% 16.667%, transparent 120deg, color-mix(in srgb, var(--fg) 50%, var(--bg)) 0 240deg, var(--bg) 0),
    conic-gradient(from 300deg at 50% 83.333%, transparent 120deg, var(--fg) 0 180deg, var(--bg) 0 240deg, color-mix(in srgb, var(--fg) 50%, var(--bg)) 0 300deg, var(--fg) 0),
    conic-gradient(from 300deg at 50% 50%, var(--fg) 120deg, color-mix(in srgb, var(--fg) 50%, var(--bg)) 0 240deg, var(--bg) 0);
  background-size: var(--size) round(calc(var(--size) * 1.732), 1px);
}
<div class="
  [--bg:#880088]
  [--fg:#b560b5]
  [--size:60px]
  [background-color:var(--bg)]
  [background-image:conic-gradient(from_120deg_at_50%_16.667%,_transparent_120deg,_color-mix(in_srgb,_var(--fg)_50%,_var(--bg))_0_240deg,_var(--bg)_0),_conic-gradient(from_300deg_at_50%_83.333%,_transparent_120deg,_var(--fg)_0_180deg,_var(--bg)_0_240deg,_color-mix(in_srgb,_var(--fg)_50%,_var(--bg))_0_300deg,_var(--fg)_0),_conic-gradient(from_300deg_at_50%_50%,_var(--fg)_120deg,_color-mix(in_srgb,_var(--fg)_50%,_var(--bg))_0_240deg,_var(--bg)_0)]
  [background-size:var(--size)_round(calc(var(--size)_*_1.732),_1px)]
"></div>
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>3D Cubes — CSS background</title>
  <style>
    html, body { height: 100%; margin: 0; }
    .bg-cubes {
      --bg: #880088;
      --fg: #b560b5;
      --size: 60px;
      background-color: var(--bg);
      background-image:
        conic-gradient(from 120deg at 50% 16.667%, transparent 120deg, color-mix(in srgb, var(--fg) 50%, var(--bg)) 0 240deg, var(--bg) 0),
        conic-gradient(from 300deg at 50% 83.333%, transparent 120deg, var(--fg) 0 180deg, var(--bg) 0 240deg, color-mix(in srgb, var(--fg) 50%, var(--bg)) 0 300deg, var(--fg) 0),
        conic-gradient(from 300deg at 50% 50%, var(--fg) 120deg, color-mix(in srgb, var(--fg) 50%, var(--bg)) 0 240deg, var(--bg) 0);
      background-size: var(--size) round(calc(var(--size) * 1.732), 1px);
    }
  </style>
</head>
<body class="bg-cubes"></body>
</html>

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

3D Cubes 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 3d cubes pattern works

This 3D cubes pattern is the classic “tumbling blocks” illusion: hexagons split into three diamond faces, shaded so each one reads as a cube. The top face uses --fg, the left face uses --bg, and the right face is a 50/50 color-mix() of the two, so you only pick two colors.

The bottom conic-gradient() sits at the center of one cube and splits the tile into three 120° slices, one per face. That’s right inside the cube, but not outside it. The other two layers fix the edges. One sits on the cube’s top point and leaves a downward 120° wedge transparent, painting only the area above it. The other sits on the bottom point and paints only the area below. Each fills in the faces of the neighboring cubes.

--size is the cube’s width. The tile is √3 times taller, rounded to whole pixels.

Use this isometric cube pattern for game and toy brands, building or architecture themes, and retro hero sections.