Apply a gradient fill
Define a Gradient swatch with GradientStops, point a shape's FillColor at it, and orient it with GradientFillAngle, GradientFillStart and GradientFillLength.
A gradient in IDML is a named swatch, applied to a shape exactly the way a flat colour is. Its direction belongs to the shape.
In short A Gradient is defined once in Resources/Graphic.xml, with two or more
GradientStop children that each name an existing <Color> swatch. A shape uses it by
pointing its FillColor at the gradient's Self id, the same attribute that takes a
colour. The shape orients the blend: GradientFillAngle turns a linear gradient,
counter-clockwise from left-to-right, so at 90 the first stop is at the bottom. A
radial gradient is centred at the shape's GradientFillStart, with GradientFillLength
as its radius. Download the sample.
The recipe
- Make sure the stop colours exist. A gradient holds no colour of its own; each stop
names an existing
<Color>swatch. The example definesColor/SunandColor/Skyas ordinary CMYK process colours. - Define the
<Gradient>swatch inResources/Graphic.xml, next to the colours. Give it aSelfid (what shapes will reference), aName, andType="Linear"orType="Radial". - Add the
<GradientStop>children. Each names a colour inStopColorand places it withLocation, a percentage from0to100. The example putsColor/Sunat0andColor/Skyat100. A stop'sMidpointgoverns the blend before that stop: it places the half-and-half point between the previous stop and this one, as a percentage of that segment (50is halfway). In real documents a non-default midpoint therefore sits on a later stop, usually the last one atLocation="100"; the first stop's midpoint has no segment to act on. - Apply it to a shape. Set the shape's
FillColorto the gradient'sSelfid. In the example the rectangle carriesFillColor="Gradient/SkySun". - Orient it on the shape, not on the gradient, so one swatch can fill several shapes in
different directions:
- for a linear gradient,
GradientFillAnglein degrees.0runs the stops from left to right, and the angle turns counter-clockwise from there, so90runs them from bottom to top. The example uses90, and InDesign drawsColor/Sun, the first stop, at the bottom of the rectangle. - for a radial gradient,
GradientFillStart(a point in the shape's own coordinates) is the centre, andGradientFillLength(in points) the radius at which the last stop is reached.
- for a linear gradient,
A linear Gradient swatch with two stops, applied to a rectangle by FillColor and
turned with GradientFillAngle="90": the first stop, yellow, at the bottom.
| Attribute · GradientStop | Values | Paged | paged.set |
|---|---|---|---|
| Location | integer / real | read · written | |
| StopColor | Color reference | read · written | |
| Midpoint | integer / real | read · written | |
| Self | text | not read |
Things to get right
- Define the gradient in the palette. A
FillColorthat names a gradientGraphic.xmldoes not define has nothing to paint with. - Stops name colours, never values. You cannot write
0 15 90 0on a stop; write a<Color>swatch and name itsSelf. Editing that swatch then updates every gradient that uses it. - Put a midpoint on the stop it leads into. To skew the blend between two stops, set
Midpointon the second of them, not the first. - Keep stops in ascending
Location. Two stops are the minimum; each extra stop adds a band. - Mind the direction of the angle. It is easy to read
90as "downwards", as screen coordinates would suggest. In InDesign it means upwards: the first stop at the bottom. - A tint is a different mechanism. For a lighter version of one colour rather than a blend between two, use a tint — see gradients & tints.
In Paged: linear and radial gradients, midpoints and
GradientFillStartfor radial gradients are read and drawn. Paged currently drawsGradientFillAngle="90"from top to bottom, the opposite of InDesign; the example above shows the difference against InDesign's own rendering. It also applies a stop'sMidpointto the segment after the stop rather than before it. Supported · verified
For the palette as a whole — colours, process and spot, where swatches live — see Color & swatches.
Frequently asked questions
How does a shape reference a gradient?
It points its FillColor at the gradient's Self id, exactly as it would at a colour. In
the example the rectangle carries FillColor="Gradient/SkySun". There is no separate
gradient-fill attribute.
Do gradient stops store their own colours?
No. Each <GradientStop> names an existing <Color> swatch in StopColor. That
indirection is why editing one swatch updates every gradient that uses it.
Which way does GradientFillAngle turn?
Counter-clockwise from left-to-right. At 0 the first stop is on the left; at 90 the first
stop is at the bottom and the last at the top. InDesign's rendering of the example shows
the first stop, yellow, at the bottom of the rectangle.
Where is a radial gradient centred?
At the shape's GradientFillStart, a point in the shape's own coordinates, with
GradientFillLength as the radius. The angle does not change how a circle looks.
What's the difference between a gradient and a tint? A gradient blends between two or more colours across a shape; a tint is a lighter version of one colour. See gradients & tints.
Build a table in a story
A recipe for authoring an IDML Table — nest it on a paragraph, declare its grid with row, column, and cell counts, then give each Cell its own paragraph.
Place an image in a frame
Place a picture in IDML — nest an Image in a Rectangle, give it its own ItemTransform and GraphicBounds, and link the file with Link/LinkResourceURI.