Skip to main content

Colour and Paint

The paint keys of a style: the colour of text, what is painted behind a box, how an svg shape is filled and stroked, and the shape a block is clipped to. The keys and their values are CSS's and SVG's, camelCased. Borders are on Borders, and padding and the box itself on Box model.

Colour values​

Every key that takes a colour - color, backgroundColor, fill, stroke, a border's colour, a gradient stop, a shadow - reads the same vocabulary, CSS Color 4's:

FormExamplesNotes
Hex with #: 3, 4, 6 or 8 digits#F53, #F538, #FF5733, #FF573380The 4th and 8th digits are alpha.
Hex without #: 6 or 8 digitsFF5733, FF573380
rgb() / rgba(), with commas or spacesrgb(18, 52, 86), rgb(18 52 86), rgba(18, 52, 86, 0.5), rgb(18 52 86 / 25%)A channel is 0-255 or a percentage; alpha is 0-1 or a percentage. A value out of range is clamped (rgb(300, -20, 128) is a pink), and none is zero.
A CSS colour namerebeccapurple, CornflowerBlue, darkslategreyAll 148 names, in any case, British grey spellings included.
transparent, nonePaint nothing.
device-cmyk()device-cmyk(0 81% 81% 30%), device-cmyk(0, 0.81, 0.81, 0.3), device-cmyk(0 0 0 1 / 50%)Four inks, 0-1 or percentages, and an optional alpha; converted to RGB by CSS Color 5's formula, so the first example is rgb(178 34 34).

Anything else - hsl(), currentcolor, #12345, a misspelt name - is not a colour: the render reports it in a WARNING naming the key and the value, and the key is ignored. No colour is guessed from a bad string.

A colour's alpha applies wherever it paints: a half-transparent text colour, border or background is drawn half-transparent.

Text colour and opacity​

KeyTakesDefaultWhat it does
colora colourblackColour of the text. transparent paints nothing, and the text is still there to select, search and read aloud. On an svg shape, color is not its fill.
opacity0 (invisible) to 1 (opaque)1Fades the element and everything it draws: a block's text, background, borders, caption and nested blocks, a table cell and all it holds, an svg shape or group.

In svg, opacity multiplies down the tree: a shape at 0.4 in a group at 0.5 is drawn at 0.2. Each child of a faded group is faded on its own, so where two children overlap the overlap shows; the render says so in a NOTICE.

Backgrounds​

KeyTakesDefaultWhat it does
backgroundColora colourtransparentColour behind the box's padding and content. On an svg shape it is the shape's fill; behind svg text, a wash under the text.
backgrounda colourThe same as backgroundColor: only a colour is read from this shorthand, and a value holding anything else is reported and ignored.
backgroundImageurl(path) or nonenoneAn image painted behind the box, over its background colour. The path names an asset, as an image's src does.
backgroundSizecover, contain, or a width and a height, each auto, a length or a percentage ("50% auto", "36pt")autoHow large the image is drawn. One value leaves the height auto. auto is the image's own size, a pixel being 0.75pt.
backgroundPositionone to four of left, center, right, top, bottom, a length or a percentage ("center", "20% 50%", "right 10pt bottom 5pt")0% 0%Where the first copy of the image stands in the box.
backgroundRepeatrepeatX, repeatY, or one or two of repeat, space, round, noRepeat (across, then down)repeatHow the image tiles. space spreads whole copies to the edges, round rescales the copies so a whole number fits.

A background moves nothing: a box with an image is laid exactly as the same box without one, and the image is cut at the box's edges, a table cell's included. However many copies are drawn, the file holds the image once; a background repeated more than four hundred times is reported with its size. The page's own background is set in Page setup.

{
"styles": {
"callout": {
"padding": 12,
"backgroundColor": "#FFF7E0",
"backgroundImage": "url(images/logos/vbgft-emblem-sm.png)",
"backgroundSize": "contain",
"backgroundPosition": "right center",
"backgroundRepeat": "noRepeat"
}
},
"content": [
{ "p": "Members are reminded that the annual meeting takes place on 12 March in the main hall.", "style": "callout" }
]
}

Fill and stroke​

These keys paint svg shapes and svg text. On a block that is not a drawing they do nothing, and the render names each such key and where it stands. SVG styles lists which shapes take which key.

KeyTakesDefaultWhat it does
filla colour, none, or a gradientblackThe shape's interior. Unwritten, the nearest enclosing group style's fill, else black, so an outline needs fill: "none".
fillOpacity0 to 11Transparency of the fill alone: a translucent fill under an opaque stroke.
strokea colour or nonenoneColour of a shape's outline or of a line. Unwritten, the nearest enclosing group style's stroke.
strokeWidthpoints or a length1Width of the outline or the line.
strokeOpacity0 to 11Transparency of the stroke alone.
strokeDasharrayon and off lengths in points, up to 64 ([4, 2])solidThe dash pattern. An odd-length list repeats to make it even, as in SVG; [0] is drawn solid.
strokeDashoffsetpoints or a length, negative allowed0Where in the dash pattern the line starts.
strokeLinecapbutt, round, squarebuttThe shape of line ends; round turns tiny dashes into dots.
strokeLinejoinmiter, round, bevelmiterThe shape of corners.
strokeMiterlimita number of at least 14How far a mitred corner may reach, as a multiple of the stroke width, before it is bevelled.
vectorEffectnonScalingStroke, nonenonenonScalingStroke keeps the stroke width constant inside a scaled group or symbol, so a hairline stays a hairline.

The winding rule of a compound path, fillRule, belongs to the path element itself, not to a style (Paths).

{
"styles": {
"panel": { "fill": "#2563EB", "fillOpacity": 0.25, "stroke": "#1E3A8A", "strokeWidth": 1.5 },
"guide": { "fill": "none", "stroke": "#DC2626", "strokeDasharray": [4, 2], "strokeLinecap": "round" },
"corner": { "fill": "none", "stroke": "#0F172A", "strokeWidth": 6, "strokeLinejoin": "bevel" }
},
"content": [
{
"svg": {
"title": "Paint samples",
"width": 300,
"height": 110,
"children": [
{ "rect": { "x": 10, "y": 10, "width": 120, "height": 80, "style": "panel" } },
{ "line": { "x1": 10, "y1": 100, "x2": 290, "y2": 100, "style": "guide" } },
{ "polyline": { "points": [ { "x": 160, "y": 80 }, { "x": 210, "y": 20 }, { "x": 260, "y": 80 } ], "style": "corner" } }
]
}
}
]
}

Gradients​

fill takes a gradient object in place of a colour: exactly one of linearGradient or radialGradient. Its coordinates follow the filled shape's own bounding box, so one named style tints any shape, each with its own extent.

KeyTakesDefaultWhat it does
linearGradient.angledegrees180The direction as CSS linear-gradient() gives it: 0 points up, clockwise, 90 points right, 180 points down.
linearGradient.stops, radialGradient.stopstwo to 256 stops, in order of offsetThe colours along the gradient.
stop offset0 to 10Where the stop sits. Before the first stop the colour is the first stop's, flat, and after the last the last's.
stop colora colour (required)The stop's colour.

A radial gradient runs from the shape's centre (offset 0) out to the circle that encloses its box (offset 1), so a circle reaches only offset 0.707 at its rim while a square reaches 1 in its corners.

{
"styles": {
"ribbon": { "fill": { "linearGradient": { "angle": 180, "stops": [
{ "offset": 0, "color": "#0F766E" },
{ "offset": 1, "color": "#134E4A" }
] } } },
"glow": { "fill": { "radialGradient": { "stops": [
{ "offset": 0, "color": "#FDE68A" },
{ "offset": 0.6, "color": "#F59E0B" },
{ "offset": 1, "color": "#B45309" }
] } } }
},
"content": [
{
"svg": {
"title": "A ribbon and a glow",
"width": 260,
"height": 120,
"children": [
{ "rect": { "x": 0, "y": 20, "width": 140, "height": 80, "style": "ribbon" } },
{ "circle": { "cx": 200, "cy": 60, "r": 55, "style": "glow" } }
]
}
}
]
}

Gradients written in svg markup (<linearGradient>, <radialGradient>) also take spreadMethod pad, repeat and reflect. A vector in user units (gradientUnits="userSpaceOnUse") is drawn across the shape's box instead, keeping only its angle, and a radial gradient's own radius is not kept; each such reduction is reported. See SVG markup.

Drop shadow​

dropShadow casts a shadow behind an svg shape or svg text. Only the painted parts cast it, so an unfilled shape shadows its outline. On a block it casts nothing, and the render says so.

KeyTakesDefaultWhat it does
dxpoints2Horizontal offset, positive to the right.
dypoints2Vertical offset, positive downward.
blur0 or more3How soft the edge is; 0 is a hard edge.
colora colour#000000The shadow's colour.
opacity0 to 10.4How opaque the shadow is.
{
"styles": {
"card": { "fill": "#FFFFFF", "stroke": "#CBD5E1", "dropShadow": { "dx": 0, "dy": 3, "blur": 6, "opacity": 0.3 } }
},
"content": [
{
"svg": {
"title": "A lifted card",
"width": 200,
"height": 110,
"children": [ { "rect": { "x": 10, "y": 10, "width": 160, "height": 80, "rx": 6, "style": "card" } } ]
}
}
]
}

Clip paths​

clipPath clips a box and everything in it to a shape, as CSS's clip-path does. It works on every kind of block - a paragraph, a heading, a list, a table or one of its cells, an image, a rule, columns, an svg, a table of contents, a watermark - on an inline run drawn in a style's box with [span, style], and on svg shapes and svg text (not text on a path).

ValueExampleWhat it clips to
circle()circle(), circle(40% at 50% 50%)A circle; with no radius, the largest the box holds, centred unless at says where.
ellipse()ellipse(), ellipse(50% 40% at 50% 50%)An ellipse; with no radii, the one touching all four sides.
inset()inset(6), inset(0 35% 0 0), inset(6 round 10)A rectangle inset from the box's edges, one to four values as margin takes them, its corners rounded by round.
polygon()polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%)The polygon through the points, each from the box's left and top edges.
path()path("M 0 0 L 157 0 L 157 36 Z"), path(evenodd, "…")Any outline in SVG path data, from the box's top-left corner, in CSS pixels (0.75pt each); evenodd before the data leaves overlapping parts hollow.
noneNothing: the same as no clipPath.

Lengths are points (or a length with a unit) and percentages of the box. On a block the reference box is its border box, so a cell's border and text are cut with it, and a rule is clipped over the width of its bar. On an svg shape it is the shape's box including its stroke. shape(), rect(), xywh() and a polygon's round are not read, and are reported.

{
"styles": {
"badge": { "backgroundColor": "#1A1A1A", "color": "#FFFFFF", "fontWeight": "bold", "padding": "0.5 2.5", "clipPath": "ellipse()" },
"pennant": { "backgroundColor": "#1E3A5F", "color": "#FFFFFF", "padding": 10, "width": 220, "clipPath": "polygon(0% 0%, 90% 0%, 100% 50%, 90% 100%, 0% 100%)" }
},
"content": [
{ "p": "[span, badge]3[/span] Return the signed copy before Friday." },
{ "p": "HARBOUR NOTICE", "style": "pennant" }
]
}

The same [span, style] box with a clipPath is how a number in a circle is written: Numbers in a circle.

In a DOCX​

KeyIn the DOCX
A colour's alphaText colour, borders and shading carry no alpha in WordprocessingML, so each such colour is written as it looks over the block's own background or the white page, with a NOTICE; an image or a watermark behind it does not show through. Svg drawings keep their alpha.
opacityFaded text is written with Word's own fill extension, which a consumer that does not know it ignores, keeping the text at full strength. A faded paragraph's fill and border are not faded, and under a Strict claim faded text is not carried; both are reported.
backgroundImageNot carried on a paragraph, a table or a frame, and reported with its size, repeat and position.
clipPathNot carried on a block, which is drawn whole in its box, with a NOTICE. A [span, style] run keeps one border and a shading, drawn as a rectangle around its text; its padding and clip path are reported. In a drawing, only a picture filled into a shape is clipped; other clips are reported.
strokeDasharray, strokeDashoffsetDashes are carried; the dash offset is not, and is reported.
radialGradientDrawn about the shape's centre over its box rather than over the gradient's own circle, so a round seal's rim comes out a shade darker.
textRenderingMode, textJustifySee Typography.