# Build paint stacks and gradients

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

Control a contour's color spatially with a ramp or uniformly with layered paints.



Use a gradient when position within a geometry should determine the color. Use ordered paints when multiple color contributions should cover the same region. A `fill` has one ordered list of `paint` elements, each containing one paint value. Sibling strokes follow the same geometry after the fill. [Paint and stroke rules](https://nothing.graphics/docs/format/spec/graphics#paint)

In the [runnable two-swatch scene](https://github.com/gridaco/nothing/blob/main/ncf/conformance/gradient-paint-stack.nothing), the outlined left swatch has a linear gradient in `userSpaceOnUse` units. Its ramp runs from navy at (24, 32) to teal at (80, 32), with endpoint colors covering the rest of the shape. The middle of the ramp is at x = 52. Change `x2` to 96 to move that midpoint to x = 60. The contour and dark outline keep their positions.

The right swatch layers translucent teal (`#4ABCC080`) over solid navy (`#193661FF`). At (144, 32) the combined color is approximately `#327991FF`. Reverse those two paints and that pixel becomes the opaque navy, since the navy now covers the teal.

For a ramp tied to the geometry’s size, use bounds-relative coordinates. Use a `stop` track to animate the color or position of one point on the ramp, or key drawable opacity to fade the entire assembled swatch. The preview used for these samples supports solid stacks and a single user-space linear or radial gradient. [Gradient units and stops](https://nothing.graphics/docs/format/spec/graphics#paint) · [Stop animation](https://nothing.graphics/docs/format/spec/animation#decision-on-animating-a-gradient-stop) · [Preview support](https://github.com/gridaco/nothing/blob/main/ncf/tools/ncf-preview/README.md#preview-coverage)

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