Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

repeating-linear-gradient() — repeating color bands along a line

`repeating-linear-gradient()` creates an `<image>` whose color-stop segment repeats indefinitely along the gradient line.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

repeating-linear-gradient( [ <linear-gradient-syntax> ] )

repeating-linear-gradient() creates an <image> whose color-stop segment repeats indefinitely along the gradient line.

For repeating-linear-gradient(90deg, red 0 10px, blue 10px 20px), samples at x=5, 15, 25, and 45 produce 255,0,0,255, 0,0,255,255, 255,0,0,255, and 255,0,0,255; support is true. Red returning proves a rendered 20px period.

Grammar: repeating-linear-gradient( [ <linear-gradient-syntax> ] ).

Direction 90deg points right and equals to right; omission means to bottom. The distance from the first to last stop defines the period, while red 0 10px, blue 10px 20px makes hard bands. in oklab explicitly selects an interpolation space. A 0px period, or one too fine for the output resolution, becomes the gradient’s solid average color. The gradient has no natural size and works wherever background-image accepts an image.

Examples

const render=async(value,width,height,points)=>{const svg='<svg xmlns="http://www.w3.org/2000/svg" width="'+width+'" height="'+height+'"><foreignObject width="'+width+'" height="'+height+'"><div xmlns="http://www.w3.org/1999/xhtml" style="width:'+width+'px;height:'+height+'px;background-image:'+value+'"></div></foreignObject></svg>';const image=new Image();image.src='data:image/svg+xml;charset=utf-8,'+encodeURIComponent(svg);await image.decode();const canvas=document.createElement('canvas');canvas.width=width;canvas.height=height;const context=canvas.getContext('2d');context.drawImage(image,0,0);return points.map(([x,y])=>[...context.getImageData(x,y,1,1).data].join(','))};
const value='repeating-linear-gradient(90deg, red 0 10px, blue 10px 20px)';
const pixels=await render(value,60,20,[[5,10],[15,10],[25,10],[45,10]]);
console.log('x5='+pixels[0]+'; x15='+pixels[1]+'; x25='+pixels[2]+'; x45='+pixels[3]+'; supported='+CSS.supports('background-image',value));

Result

x5=255,0,0,255; x15=0,0,255,255; x25=255,0,0,255; x45=255,0,0,255; supported=true

`repeating-linear-gradient()` creates an `<image>` whose color-stop segment repeats indefinitely along the gradient line.

Sources