CSS Reference ยท Properties for Special Contexts
The paint-order property
Reference for the CSS paint-order property: choose whether fill, stroke or markers are painted first, for crisp outlined SVG and HTML text.
The paint-order property chooses the order in which the fill, the stroke and the markers of a shape or text are painted. By default the fill is painted first and the stroke sits on top of it, so a thick stroke eats into the inside of the shape.
Its best-known use is outlined text: paint the stroke first and the fill on top, and the letters keep their full shape while the outline appears only outside.
text { stroke: black; stroke-width: 6; paint-order: stroke fill; }
Try it
Syntax
paint-order: normal | [ fill || stroke || markers ];
- Initial value:
normal - Applies to: SVG shapes and text; also supported on HTML text in current browsers
- Inherited: yes
- Animatable: no
- Computed value: as specified
Values
| Value | Description |
|---|---|
normal |
The default order: fill, then stroke, then markers. |
stroke fill |
Stroke first, then fill on top (markers last). |
markers |
Markers are painted first when it is listed first, for example markers stroke fill. |
| Partial lists | Items you leave out follow in their default order. paint-order: stroke means stroke, fill, markers. |
Usage notes
- Half the stroke disappears. Because the stroke is centered on the edge, painting it first and then covering the inner half with fill leaves only the outer half visible, so the visible outline is half of
stroke-width. Double the width if you need a specific size. - Sharp corners. Use
stroke-linejoin: roundso the outline around letters does not form spikes. - Legibility. A halo around text in a contrasting color is a good way to keep labels readable on busy images or maps.
- HTML text. In supporting browsers
paint-orderalso works on HTML text together with-webkit-text-stroke; check a compatibility table before relying on it. - Markers only matter for
<line>,<polyline>,<polygon>and<path>withmarker-*properties.
Browser support
Supported for SVG in current major browsers. Use on HTML text is newer; check a compatibility table.
Related
fillstrokestroke-width- Lesson: SVG paths and text