Gradient
You can apply gradients as fills or strokes.
There are two types of gradient in SVG: linear and radial gradient.
You would declare gradients inside the <defs> element, and you must give the gradient an id attribute so you can reference it.
Gradient SVG attributes
gradientUnits
Defines the coordinate system for the gradient. Specify either:
objectBoundingBox— uses the size of the object that references the gradient (the coordinate values will range from 0 to 1).userSpaceOnUse— uses the viewport coordinates (you need to know where the object is and place the gradient coordinates accordingly).
Gradient SVG elements
<linearGradient>
x1— start x coordinate (default is0%)y1— start y coordinate (default is100%)x2— end x coordinate (default is0%)y2— end y coordinate (default is0%)href— reference to another<linearGradient>that will be used as a templategradientUnits— defines the coordinate system for attributesx1,y1,x2,y2: specifyuserSpaceOnUse(use the viewport coordinate) orobjectBoundingBox(use the bounding box of the element that references this gradient)spreadMethod— defines how the shape is filled beyond the defined edges of the gradient; specifypad(just use the edge color, default),reflect, orrepeatgradientTransform— space-separated CSS transform functions, e.g.skewX(20) translate(-35, 0)
| LIVE PREVIEW
<radialGradient>
cx— x coordinate of the end circle's center (default is50%)cy— y coordinate of the end circle's center (default is50%)r— radius of the end circle (default is50%)fx— x coordinate of the start circle's center (default is the same ascx)fy— y coordinate of the start circle's center (default is the same ascy)fr— radius of the start circle (default is0%)href— reference to another<linearGradient>that will be used as a templategradientUnits— defines the coordinate system for attributescx,cy,r,fx,fy,fr: specifyuserSpaceOnUse(use the viewport coordinate) orobjectBoundingBox(use the bounding box of the element that references this gradient)spreadMethod— defines how the shape is filled beyond the defined edges of the gradient; specifypad(just use the edge color, default),reflect, orrepeatgradientTransform— space-separated CSS transform functions, e.g.skewX(20) translate(-35, 0)
| LIVE PREVIEW
Stop SVG element
<stop>
Represents a color stop in a gradient vector.
offset— where the stop is; specify a number like0.5or50%stop-color— color of the stop, e.g.#ff0000stop-opacity— opacity of the stop, e.g.1
References
- Gradients in SVG (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Gradients
- <linearGradient> (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Element/linearGradient
- <radialGradient> (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Element/radialGradient
- gradientUnits (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/gradientUnits
- spreadMethod (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/spreadMethod
- gradientTransform (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/gradientTransform
- <stop> (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Element/stop