<gradient>
Map an ordered color ramp into a shape's local coordinates.
Examples
Download the complete .nothing source · Source on GitHub
Rendered with ncf-preview at 208 × 64.

<scene width="208" height="64">
<shape>
<rect anchor-u="0" anchor-v="0" offset-x="8" offset-y="8" width="88" height="48" corner-radius="12"/>
<fill>
<paint>
<gradient type="linear" gradientUnits="userSpaceOnUse" x1="24" y1="32" x2="80" y2="32">
<stop offset="0" stop-color="#193661FF"/>
<stop offset="1" stop-color="#4ABCC0FF"/>
</gradient>
</paint>
</fill>
<stroke stroke-width="2"><paint><solid color="#122947FF"/></paint></stroke>
</shape>
<shape>
<rect anchor-u="0" anchor-v="0" offset-x="112" offset-y="8" width="88" height="48" corner-radius="12"/>
<fill>
<paint><solid color="#193661FF"/></paint>
<paint><solid color="#4ABCC080"/></paint>
</fill>
</shape>
</scene>A gradient gives each point a ramp position, then evaluates its ordered stops using straight sRGB channels and alpha.
Syntax
Run a local ramp from navy to teal
Choose local coordinates and place the endpoints at x = 24 and x = 80. At x = 52 the ramp is halfway between colors. At x = 86 it holds the last color.
<gradient type="linear" gradientUnits="userSpaceOnUse" x1="24" y1="32" x2="80" y2="32">
<stop offset="0" stop-color="#193661FF"/>
<stop offset="1" stop-color="#4ABCC0FF"/>
</gradient>Complete .nothing source · Sample checks
Usage context
Allowed parents are <paint>.
Supply the points and positive radii required by the sampled type. A linear gradient requires distinct endpoints. Linear and radial authors explicitly set gradientUnits to userSpaceOnUse.
Attributes
type
Value linear, radial, sweep, diamond · Required · Keys Held
Choose the geometry that maps local positions onto the ramp.
gradientUnits
Value userSpaceOnUse · Keys Held
Local coordinates. Required for linear and radial gradients.
cx
Value local units · Keys Scalar
Center x coordinate, required for radial, sweep and diamond gradients.
cy
Value local units · Keys Scalar
Center y coordinate, required for radial, sweep and diamond gradients.
r
Value local units · Keys Scalar
Positive radius, required for a radial gradient.
rx
Value local units · Keys Scalar
Positive horizontal radius, required for a diamond gradient.
ry
Value local units · Keys Scalar
Positive vertical radius, required for a diamond gradient.
x1
Value local units · Keys Scalar
Horizontal coordinate of the first endpoint, required for a linear gradient.
y1
Value local units · Keys Scalar
Vertical coordinate of the first endpoint, required for a linear gradient.
x2
Value local units · Keys Scalar
Horizontal coordinate of the second endpoint, required for a linear gradient.
y2
Value local units · Keys Scalar
Vertical coordinate of the second endpoint, required for a linear gradient.
Children
| Elements | Cardinality | Declared by | Role and source order |
|---|---|---|---|
<stop> | Zero or more | <gradient> | Zero stops give transparent paint. One stop gives a consistent color across the ramp. Document order. Effective offsets never decrease, and later stops win at a shared position. |
<animate> | Zero or more | Animation | A track targets one keyable property on this owner. For equal first-key times, the later track in document order wins. Evaluating animation tracks |