# `<gradient>`

[Canonical page](https://nothing.graphics/docs/format/reference/gradient) · [Page source on GitHub](https://github.com/gridaco/nothing/blob/main/ncf/docs/reference/gradient.md)

Map an ordered color ramp into a shape's local coordinates.

## Examples

[Download the complete .nothing source](https://nothing.graphics/format/paint-stack/source.nothing) · [Source on GitHub](https://github.com/gridaco/nothing/blob/main/ncf/conformance/gradient-paint-stack.nothing)

Rendered with ncf-preview at 208 × 64.

- [Still · Ramp and paint stack](https://nothing.graphics/format/paint-stack/0.webp) at 0s. The outlined swatch at the left transitions from navy to teal. The swatch at the right uses a translucent teal paint over solid navy.

```xml
<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>
```



<!-- Generated by ncf/tools/reference/generate.mjs. -->

A gradient gives each point a ramp position, then evaluates its ordered stops using straight sRGB channels and alpha.

## Syntax [#syntax]

### Run a local ramp from navy to teal [#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.

```xml
<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](https://github.com/gridaco/nothing/blob/main/ncf/conformance/gradient-paint-stack.nothing) · [Sample checks](https://github.com/gridaco/nothing/blob/main/ncf/conformance/README.md#published-reference-examples)

## Usage context [#usage-context]

Allowed parents are [`<paint>`](https://nothing.graphics/docs/format/reference/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 [#attributes]

[Property animation](https://nothing.graphics/docs/format/spec/animation#property-types-and-exceptions)

### `type` [#type]

**Value** `linear`, `radial`, `sweep`, `diamond` · **Required** · **Keys** Held

Choose the geometry that maps local positions onto the ramp.

### `gradientUnits` [#gradientunits]

**Value** `userSpaceOnUse` · **Keys** Held

Local coordinates. Required for linear and radial gradients.

### `cx` [#cx]

**Value** local units · **Keys** Scalar

Center x coordinate, required for radial, sweep and diamond gradients.

### `cy` [#cy]

**Value** local units · **Keys** Scalar

Center y coordinate, required for radial, sweep and diamond gradients.

### `r` [#r]

**Value** local units · **Keys** Scalar

Positive radius, required for a radial gradient.

### `rx` [#rx]

**Value** local units · **Keys** Scalar

Positive horizontal radius, required for a diamond gradient.

### `ry` [#ry]

**Value** local units · **Keys** Scalar

Positive vertical radius, required for a diamond gradient.

### `x1` [#x1]

**Value** local units · **Keys** Scalar

Horizontal coordinate of the first endpoint, required for a linear gradient.

### `y1` [#y1]

**Value** local units · **Keys** Scalar

Vertical coordinate of the first endpoint, required for a linear gradient.

### `x2` [#x2]

**Value** local units · **Keys** Scalar

Horizontal coordinate of the second endpoint, required for a linear gradient.

### `y2` [#y2]

**Value** local units · **Keys** Scalar

Vertical coordinate of the second endpoint, required for a linear gradient.

## Children [#children]

| Elements                                                              | Cardinality  | Declared by  | Role and source order                                                                                                                                                                                                |
| --------------------------------------------------------------------- | ------------ | ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [`<stop>`](https://nothing.graphics/docs/format/reference/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>`](https://nothing.graphics/docs/format/reference/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](https://nothing.graphics/docs/format/spec/animation#evaluation) |

## Specifications [#specifications]

* [Paint](https://nothing.graphics/docs/format/spec/graphics#paint)
* [Evaluating animation tracks](https://nothing.graphics/docs/format/spec/animation#evaluation)
