CSS Reference ยท Functions
The repeating-linear-gradient() function
Reference for the CSS repeating-linear-gradient() function: how the stop range repeats, building stripes, hatching and rulers, with live examples.
The repeating-linear-gradient() function works like linear-gradient(), but the list of color stops repeats in both directions along the gradient line instead of stopping at the last color. It is the CSS way to draw stripes, hatching, caution tape or ruler marks without an image file.
CSS
.tape { background: repeating-linear-gradient(45deg, #facc15 0 12px, #111827 12px 24px); }
Try it
Syntax
CSS
repeating-linear-gradient(
[ <angle> | to <side-or-corner> ]? [ in <color-space> ]?,
<color-stop-list>
)
It takes the same arguments as linear-gradient(). The result is an <image>.
Syntax and arguments
| Argument | Description |
|---|---|
| Direction | An angle or to ... keyword. Default to bottom. |
| Color stops | Positions must be lengths (or percentages of the gradient line). The distance from the first to the last stop is the length of one repeat. |
Usage notes
- The repeat length is last stop minus first stop. With
red 0, blue 20pxit is20px. If the stops use only percentages, the pattern fits the box once and appears not to repeat; use lengths. - Hard stripes need paired stops.
a 0 10px, b 10px 20pxgives crisp bands; without the pairing the colors blend. - Smooth repeats. If the first and last colors differ (as in the red-green example), there is a visible jump at each repeat; end with the first color to make a seamless wave.
- Edge quality. Diagonal hard stops can look jagged at some sizes. A tiny blend, such as stopping one pixel apart, can smooth edges.
- Prefer
background-sizetiles for complex patterns, since a normal gradient in a small repeating tile is often cheaper than a huge repeating one. - Decoration only. Stripes carry no meaning for assistive technology; do not rely on them to convey information.
Browser support
Supported in every modern browser.