Repeating Linear Gradient in CSS

Create seamless striped patterns and textures efficiently with CSS repeating-linear-gradient(). Complete syntax reference and practical examples.

The repeating-linear-gradient() CSS function is a powerful tool that extends the capabilities of linear gradients by automatically repeating the gradient pattern infinitely. Instead of manually stacking multiple linear gradients or using background-size tricks, this function allows developers to create seamless stripes, textures, and patterns with elegant, maintainable code. Understanding this function opens up possibilities for creating visual effects that would otherwise require images or complex CSS workarounds. For teams focused on web performance optimization, using CSS gradients instead of image files can significantly reduce page load times and improve the overall user experience.

Related resources

Complete Syntax Reference

The function creates repeating linear gradients with this syntax:

background: repeating-linear-gradient(angle | to direction, color-stop1, color-stop2, ...);

The function returns an object of the <gradient> data type, which is a special kind of <image> that can be used wherever <image> values are accepted.

Syntax Parameters
ParameterDescriptionValues
angleThe gradient line's angle of directiondeg, rad, grad, turn (0deg = up, positive = clockwise)
to directionStarting point using keywordsto top, to bottom, to left, to right, to top left, etc.
color-stopColor value with optional positioncolor [position], e.g., "#ff6b6b 20px"
color-hintInterpolation hint between stopspercentage or length, e.g., "25%" between stops

Practical Examples

Basic Striped Pattern

background: repeating-linear-gradient(
  45deg,
  #ff6b6b,
  #ff6b6b 20px,
  #4ecdc4 20px,
  #4ecdc4 40px
);

This creates diagonal stripes at 45 degrees with alternating red and teal colors. The pattern repeats every 40 pixels (the distance between the first color start and the last color end).

Common Repeating Gradient Patterns
1/* Vertical stripes */2background: repeating-linear-gradient(3  to right,4  #2c3e50,5  #2c3e50 10px,6  #e74c3c 10px,7  #e74c3c 20px8);9 10/* Horizontal stripes (default) */11background: repeating-linear-gradient(12  #f1c40f,13  #f1c40f 15px,14  #2ecc71 15px,15  #2ecc71 30px16);17 18/* Complex multi-color pattern */19background: repeating-linear-gradient(20  60deg,21  #667eea 0px,22  #667eea 10px,23  #764ba2 10px,24  #764ba2 20px,25  #f093fb 20px,26  #f093fb 30px27);

Understanding Angles

The angle system follows a compass-like pattern:

AngleDirectionDescription
0degGradient points upward (toward 12 o'clock)
90degGradient points to the right
180degGradient points downward (default)
270degGradient points to the left
-90degSame as 270deg

Positive angles rotate clockwise, negative angles rotate counterclockwise.

Advanced Techniques

Combining Multiple Gradient Layers

You can layer multiple gradients by separating them with commas:

background:
  repeating-linear-gradient(
    90deg,
    transparent,
    transparent 50px,
    rgba(255, 255, 255, 0.1) 50px,
    rgba(255, 255, 255, 0.1) 100px
  ),
  repeating-linear-gradient(
    0deg,
    #1a1a2e,
    #1a1a2e 25px,
    #16213e 25px,
    #16213e 50px
  );

The first gradient in the list renders on top. This technique creates complex patterns from simple building blocks.

Browser Compatibility
BrowserVersionRelease Date
Chrome26+July 2015
Firefox16+October 2012
Safari7+September 2013
Edge12+July 2015
Opera12.1+December 2012
iOS Safari7+September 2013
Android Chrome26+July 2015
Optimization Tips

Keep It Simple

Prefer simple gradients over complex layered ones for better performance

Use Custom Properties

Define reusable gradient patterns with CSS custom properties

Test on Target Devices

Verify performance on the devices your users actually use

Balance Aesthetics

Find the right balance between visual appeal and rendering performance

Common Mistakes and Solutions

Mistake 1: Incorrect Color Stop Distance

Problem: Pattern looks uneven or too compressed. Solution: Calculate color stop positions based on desired pattern frequency. For a 20px stripe pattern, use stops at 0px, 20px, 40px, etc.

Mistake 2: Forgetting the Repeating Behavior

Problem: Expecting a single gradient cycle. Solution: Remember that ALL color stops repeat infinitely. The pattern is one complete cycle from first to last stop.

Mistake 3: Mismatched Start and End Colors

Problem: Visible seams between pattern repetitions. Solution: Ensure the last color stop matches the first for seamless patterns. For a striped pattern, make sure the transition from the last color back to the first color is smooth.

Mistake 4: Confusing Angle Direction

Problem: Gradient goes opposite of expected direction. Solution: Remember: 0deg is upward, positive angles rotate clockwise. Test with small values first.

Frequently Asked Questions

Summary

The repeating-linear-gradient() function is an essential tool for creating efficient, scalable patterns in CSS. Key takeaways:

  • The function creates infinite patterns from gradient definitions
  • The distance between first and last color stop determines one complete pattern cycle
  • Use angles (deg) or direction keywords (to top, to right, etc.) to control orientation
  • Combine multiple gradients for complex layered patterns
  • Browser support is excellent across all modern browsers
  • Consider performance when using gradients on large or animated areas

Mastering this function enables you to create sophisticated visual effects with clean, performant CSS code—no images required. For teams implementing AI-powered web solutions, efficient CSS patterns like these contribute to faster load times and better user engagement metrics.

Master CSS for High-Performance Websites

Learn more CSS techniques for creating efficient, visually stunning web experiences.