The SVG <linearGradient> element defines a reusable linear color blend. Put it in <defs>, give it an id, add <stop> colors, then paint shapes with fill="url(#id)" or stroke="url(#id)".
Direction comes from the vector x1, y1, x2, y2 (default left to right). For circular blends, see radial gradients.
Baseline · Widely available.
<linearGradient> and <stop> are stable across modern browsers since about July 2015.
Deprecated: xlink:href.
Do not reuse gradients with xlink:href. Prefer a full local definition, or the modern href attribute when you need a template reference.
Not painted alone.
The gradient definition is invisible until a shape references it with url(#id).
Optional:gradientTransform="rotate(...)" can tilt further.
Edge Cases & Pitfalls
Most broken gradients are ids, missing url(), or unit surprises.
id
url(#id) must match
Typos or duplicate ids mean a solid black/default fill instead of your blend.
units
objectBoundingBox is default
Percent vectors scale with the shape. Use userSpaceOnUse when you need absolute coordinates.
stops
Need at least two stops
One stop alone cannot blend. Add distinct offsets and colors.
stroke
Thin strokes hide blends
When using stroke="url(#id)", raise stroke-width so the gradient band is visible.
Compatibility
Browser Support
SVG <linearGradient> is supported in every modern browser.
✓ Baseline · Widely available
SVG <linearGradient>
Widely available since about July 2015. Chrome, Firefox, Safari, Edge, and Opera support linearGradient, stop, and url(#id) paint servers. Internet Explorer 9+ supports basic SVG gradients.
98%Global support (approx.)
Google ChromeAll modern
Full support
Mozilla FirefoxAll modern
Full support
Apple SafariAll modern
Full support
Microsoft EdgeAll modern
Full support
OperaAll modern
Full support
Samsung InternetAll modern
Full support
Internet Explorer9+
Supported
<linearGradient>Widely supported
Bottom line: Safe for production icons, charts, and UI fills. Prefer local defs with unique ids over deprecated xlink:href reuse.
Remember
Key Takeaways
Define in <defs> with an id.
Direction:x1, y1, x2, y2.
Colors:<stop offset stop-color>.
Apply:fill or strokeurl(#id).
One line: stops in <linearGradient>, paint with url(#id).
UA style
Default CSS Settings
Gradients are paint servers — they have no visible box of their own. Useful defaults to remember:
defaults.css
/* Conceptual defaults */
linearGradient {
/* x1=0% y1=0% x2=100% y2=0% → left to right */
/* gradientUnits: objectBoundingBox */
/* spreadMethod: pad */
}
/* Apply from CSS if needed */
.shape {
fill: url(#hGrad);
}
Prefer presentation attributes in these lessons so the paint stays inside the SVG markup.
Frequently Asked Questions
Define a <linearGradient> in <defs> with an id and <stop> elements, then use fill="url(#id)" or stroke="url(#id)" on a shape.
They set the gradient vector. Defaults are left-to-right: x1="0%" y1="0%" x2="100%" y2="0%".
offset places that color along the vector, usually as a percentage such as 0%, 50%, or 100%.
Yes. Use stroke="url(#id)" and set stroke-width so the stroke band is visible.
Default gradientUnits is objectBoundingBox, so the gradient scales with the shape. Use userSpaceOnUse for fixed coordinates.
Use linear for directional blends. Use radial when color should radiate from a center point.