files/en-us/web/svg/reference/element/lineargradient/index.md
The <linearGradient> SVG element lets authors define linear gradients to apply to other SVG elements.
{{svginfo}}
x1, x2, y1, y2
Value type: userSpaceOnUse | objectBoundingBox; Default value: objectBoundingBox; Animatable: yes<linearGradient> element that will be used as a template.
Value type: <URL>; Default value: none; Animatable: yespad | reflect | repeat; Default value: pad; Animatable: yes0%; Animatable: yes100%; Animatable: yes0%; Animatable: yes0%; Animatable: yesThis element implements the {{domxref("SVGLinearGradientElement")}} interface.
html,
body,
svg {
height: 100%;
}
<svg
viewBox="0 0 10 10"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<linearGradient id="myGradient" gradientTransform="rotate(90)">
<stop offset="5%" stop-color="gold" />
<stop offset="95%" stop-color="red" />
</linearGradient>
</defs>
<!-- using my linear gradient -->
<circle cx="5" cy="5" r="4" fill="url('#myGradient')" />
</svg>
{{EmbedLiveSample('Basic linear gradient', 150, '100%')}}
In this example, the two {{SVGElement("rect")}} elements have different aspect ratios, but the angle of the gradient is the same.
html,
body,
svg {
height: 100%;
}
<svg
viewBox="0 0 500 500"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<linearGradient
id="grad"
x1="0"
y1="0"
x2="20"
y2="20"
spreadMethod="repeat"
gradientUnits="userSpaceOnUse">
<stop offset="50%" stop-color="red" />
<stop offset="50%" stop-color="gold" />
</linearGradient>
</defs>
<rect width="100%" height="25%" fill="url(#grad)" />
<rect width="100%" height="65%" fill="url(#grad)" y="30%" />
</svg>
{{EmbedLiveSample('Repeating angled gradient', 500, '100%')}}
{{Specifications}}
{{Compat}}