Striped Backgrounds in CSS (Horizontal, Vertical, Diagonal)

By Marko Denic
Contents
  1. How it works
  2. Hard color stops
  3. Horizontal stripes
  4. Vertical stripes
  5. Diagonal stripes
  6. The background-size method
  7. Practical examples
  8. Stripes over a color or image
  9. Zebra-striped table rows
  10. Animated striped progress bar
  11. Striped text
  12. FAQ

CSS stripes are made with gradients that have hard color stops: when two colors share the same position, there’s no blending, just a sharp edge. Repeat that pattern and you have stripes, with no images at all.

The easiest tool for it is repeating-linear-gradient():

background: repeating-linear-gradient(45deg, #1d4ed8 0 10px, #3b82f6 10px 20px);

Demo:

horizontal
vertical
diagonal
pinstripe
warning

How it works

Hard color stops

Each color stop can take two positions: where it starts and where it ends. #1d4ed8 0 10px means “solid blue from 0 to 10px”. When the next color starts exactly where the previous one ends, the edge is sharp.

css
/* Smooth: blue fades into light blue */
background: linear-gradient(#1d4ed8, #bfdbfe);

/* Sharp: half blue, half light blue */
background: linear-gradient(#1d4ed8 50%, #bfdbfe 50%);

Horizontal stripes

Gradients run top to bottom by default, so the stripes are horizontal. One stripe pair is 24px tall and repeats forever.

css
.horizontal {
  background: repeating-linear-gradient(
    #bfdbfe 0 12px,
    #fff 12px 24px
  );
}

Vertical stripes

Rotate the gradient 90 degrees so it runs left to right.

css
.vertical {
  background: repeating-linear-gradient(
    90deg,
    #bfdbfe 0 12px,
    #fff 12px 24px
  );
}

Diagonal stripes

Any angle works. 45deg slants up to the right, -45deg the other way. repeating-linear-gradient keeps diagonal stripes seamless, which is hard with the background-size trick below.

css
.diagonal {
  background: repeating-linear-gradient(
    45deg,
    #93c5fd 0 10px,
    #dbeafe 10px 20px
  );
}

The background-size method

Older tutorials draw one stripe pair with linear-gradient and tile it with background-size. It works perfectly for horizontal and vertical stripes, and it makes it easy to change the spacing with one value.

css
.stripes {
  background: linear-gradient(#bfdbfe 50%, #fff 50%);
  background-size: 100% 24px; /* each tile is one stripe pair */
}

Practical examples

Stripes over a color or image

Use semi-transparent stripes and layer them over a solid color, another gradient or an image. The first background in the list is on top.

css
.card {
  background:
    repeating-linear-gradient(45deg, rgb(255 255 255 / 0.1) 0 10px, transparent 10px 20px),
    linear-gradient(135deg, #1e3a8a, #3b82f6);
}

Zebra-striped table rows

For tables, you don’t need gradients: color every other row with :nth-child(even). It makes long rows easier to follow.

css
tbody tr:nth-child(even) {
  background: #f1f5f9;
}

tbody tr:hover {
  background: #e0e7ff;
}

Animated striped progress bar

Move the background position by exactly one stripe period, and the animation loops seamlessly. For 45° stripes with a 20px period, that’s 20 × √2 ≈ 28.28px horizontally. Respect users who prefer reduced motion.

css
.progress {
  background:
    repeating-linear-gradient(45deg, rgb(255 255 255 / 0.25) 0 10px, transparent 10px 20px)
    0 0 / 28.28px 100%,
    #1d4ed8;
  animation: stripes 0.8s linear infinite;
}

@keyframes stripes {
  to { background-position: 28.28px 0, 0 0; }
}

@media (prefers-reduced-motion: reduce) {
  .progress { animation: none; }
}

Striped text

Clip the stripes to the text with background-clip: text, the same trick behind gradient text.

css
.striped-text {
  background: repeating-linear-gradient(45deg, #1d4ed8 0 4px, #60a5fa 4px 8px);
  background-clip: text;
  color: transparent;
  font-size: 4rem;
  font-weight: 900;
}

FAQ

How do I make stripes in CSS?

Use repeating-linear-gradient() with hard color stops, for example repeating-linear-gradient(45deg, #1d4ed8 0 10px, #3b82f6 10px 20px). Change the angle for horizontal (default), vertical (90deg) or diagonal stripes.

How do I change the stripe width?

Change the stop positions. In #a 0 10px, #b 10px 20px, each stripe is 10px. Make the second color wider, like #b 10px 30px, for uneven stripes.

Why are my diagonal stripes blurry or jagged?

Browsers don’t anti-alias hard gradient edges perfectly at angles. Leave about a pixel of blend between colors (#a 0 10px, #b 11px 20px) to smooth them.

Can I make polka dots the same way?

Yes, with radial-gradient() and background-size. Mix your own patterns visually in the CSS gradient generator.