CSS Background Patterns Without Images: Stripes, Dots, Grids and Checks
Decorative backgrounds used to mean small tiled images: a 10×10 pixel GIF for stripes, a dot PNG for polka dots. Each one was another file to download and another asset to re-export when the color changed. CSS gradients can draw most simple geometric patterns directly, at any resolution and in any color, with one or two lines of code.
The key trick: hard color stops
A gradient normally blends smoothly from one color to the next. But if two color stops share the same position, there is no room to blend, so the color changes instantly:
background: linear-gradient(90deg, #141414 50%, #e8dcc4 50%);That’s a sharp split, half dark and half beige. Shrink the background to a small tile with background-size or use a repeating- gradient, and the split becomes a pattern. Modern CSS also allows a shorthand where one color has two positions: #141414 0 10px means “this color from 0 to 10px”.
Five classic patterns
Stripes
background: repeating-linear-gradient(45deg, #e8dcc4 0 6px, #faf7f2 6px 24px);The first color runs from 0 to 6px, the second from 6px to 24px, and the pattern repeats every 24px along the 45° direction. Change the angle to 0deg or 90deg for horizontal or vertical stripes.
Polka dots
background-color: #faf7f2;
background-image: radial-gradient(circle, #e8dcc4 6px, transparent 6.5px);
background-size: 24px 24px;Each 24px tile has one circle in its center. The half-pixel difference between 6px and 6.5px adds a tiny bit of anti-aliasing, so dot edges look smooth instead of jagged.
Grid paper
background-color: #faf7f2;
background-image:
linear-gradient(#e8dcc4 1px, transparent 1px),
linear-gradient(90deg, #e8dcc4 1px, transparent 1px);
background-size: 24px 24px;Two gradients: one draws a 1px horizontal line at the top of each tile, the other a vertical line on the left. Together they form a grid. Add a second, larger grid in a darker color for “major” lines every five squares.
Checkerboard
background-color: #faf7f2;
background-image: conic-gradient(#e8dcc4 25%, transparent 0 50%, #e8dcc4 0 75%, transparent 0);
background-size: 32px 32px;A conic gradient sweeps around the tile’s center and colors two opposite quarters, which is exactly one checkerboard tile. Before conic gradients, this needed two or four linear gradients with offsets.
Cross-hatch
Two repeating stripe gradients at 45° and −45°, layered over a background color, create a fine hatched texture.
All of these are available with live controls in the CSS pattern generator above.
CSS patterns versus other options
| Approach | File size | Resolution | Recolor | Complexity it handles |
|---|---|---|---|---|
| CSS gradients | Zero extra requests, a few bytes | Infinite | Change a value | Simple geometry |
| SVG tile (inline or data URI) | Small | Infinite | Edit the SVG or use CSS variables | Any vector shape |
| PNG tile | Small to medium | Fixed (blurry when scaled) | Re-export | Anything, including textures |
| Large background photo | Large | Fixed | Re-export | Photographic |
CSS is ideal for stripes, dots, grids and checks. For more complex motifs, such as leaves, waves or logos, an SVG tile is the better choice. For organic textures like paper or grain, a small PNG works best; our noise texture generator creates tileable grain.
Keeping a pattern in the background
Keep contrast low behind content. A pattern is decoration. If text sits on top, use two colors that are very close in lightness, so the pattern reads as texture rather than noise. Then check the text against the darker of the two colors with a contrast checker.
Use whole-pixel sizes. Stripe widths and tile sizes that land on whole pixels look crisp. Fractional sizes can produce uneven stripes or blurry edges, especially on standard-density screens.
Diagonal stripes can shimmer. Thin diagonal lines may show slight inconsistencies due to anti-aliasing. Slightly wider stripes or sizes that are multiples of 2 or 4 usually look cleaner.
Use patterns with purpose. Diagonal yellow-and-black stripes signal caution or “under construction” almost universally. Grid paper suggests planning and precision, which is why many design tools use it as a canvas background. Polka dots feel playful and retro.
Watch out for moiré. Fine patterns can create shimmering interference effects when scaled, scrolled or viewed on screens with a different pixel density. If a pattern flickers while scrolling, make it larger or lower its contrast.
Patterns and performance
Gradient patterns are rendered by the browser and are generally cheap. Very complex stacks of many gradients over huge areas can increase paint time, but typical patterns with one to three layers have no noticeable cost. Animated patterns (for example moving stripes on a progress bar) are best done by animating background-position, which is fine for small elements.
Using patterns in themes
Put the colors into custom properties, and the same pattern adapts to light and dark mode automatically:
.pattern {
--pattern-bg: #faf7f2;
--pattern-fg: #e8dcc4;
background: repeating-linear-gradient(45deg, var(--pattern-fg) 0 6px, var(--pattern-bg) 6px 24px);
}
@media (prefers-color-scheme: dark) {
.pattern { --pattern-bg: #141414; --pattern-fg: #2a2723; }
}Patterns behind text
Busy patterns behind text make reading harder for everyone, and particularly for people with dyslexia or low vision. High-contrast stripes can be uncomfortable for people with visual stress or photosensitivity. Keep patterns subtle, avoid placing body text directly on them, and never use a pattern as the only way to convey information unless it is paired with a legend or label (patterns in charts are a good addition to color for color-blind users).