CSS paint-order Property

The CSS paint-order property controls the order in which an element's fill, stroke, and markers are painted.

It is primarily used with SVG graphics and can also control the painting order of text fill and stroke. By changing the default order, developers can place a stroke behind a fill, improve outlined text, or adjust how SVG shapes and markers overlap.

paint-order Syntax

The paint-order property accepts normal or a space-separated sequence of one to three painting components.

Basic Syntax

selector {
  paint-order: stroke;
}

This paints the stroke first, followed by the fill and markers in their default relative order.

Default Painting Order

selector {
  paint-order: normal;
}

The default order is fill, stroke, and then markers.

Single-Value Syntax

.shape {
  paint-order: fill;
}
.shape {
  paint-order: stroke;
}
.shape {
  paint-order: markers;
}

The specified component is painted first. Any omitted components follow in their default relative order.

Multiple-Value Syntax

.shape {
  paint-order: stroke fill;
}
.shape {
  paint-order: markers stroke;
}
.shape {
  paint-order: stroke markers fill;
}

Each component can appear only once. Omitted components are appended in their default relative order.

CSS-Wide Keywords

.shape {
  paint-order: initial;
}
.shape {
  paint-order: inherit;
}
.shape {
  paint-order: unset;
}
.shape {
  paint-order: revert;
}
.shape {
  paint-order: revert-layer;
}

CSS-wide keywords must be used individually and cannot be combined with painting components.

Property Values

Value Description
normal Paints the fill first, stroke second, and markers last.
fill Paints the fill first, followed by the remaining components in their default order.
stroke Paints the stroke first, followed by fill and markers.
markers Paints SVG markers first, followed by fill and stroke.
stroke fill Paints stroke, then fill, then markers.
markers stroke Paints markers, then stroke, then fill.
stroke markers fill Paints stroke, then markers, then fill.
initial Resets the property to normal.
inherit Uses the computed painting order from the parent element.
unset Uses the inherited value because the property is inherited.
revert Reverts the property according to CSS cascade origin rules.
revert-layer Reverts the property according to CSS cascade layer rules.

Property Characteristics

Characteristic Value
Initial value normal
Inherited Yes
Applies to Text and SVG graphics elements
Computed value As specified
Animation type Discrete
Percentages Not applicable
Default order Fill, stroke, markers
Primary use SVG graphics and outlined text

Valid Values

.shape {
  paint-order: normal;
}
.shape {
  paint-order: stroke;
}
.shape {
  paint-order: fill stroke;
}
.shape {
  paint-order: markers fill stroke;
}
.shape {
  paint-order: stroke markers;
}

Invalid Values

.shape {
  paint-order: reverse;
}
.shape {
  paint-order: stroke stroke;
}
.shape {
  paint-order: 1 2 3;
}
.shape {
  paint-order: fill stroke markers fill;
}

The property does not accept reverse, numeric values, repeated components, or more than three painting components.

How It Works

SVG graphics and stroked text can have multiple painting components. The paint-order property determines which component is drawn first and which appears above the others.

Normal Painting Order

.shape {
  fill: #2563eb;
  stroke: #111827;
  stroke-width: 12px;
  paint-order: normal;
}

The fill is painted first. The stroke is painted over the fill, so part of the stroke can cover the shape's interior.

Painting the Stroke First

.shape {
  fill: #2563eb;
  stroke: #111827;
  stroke-width: 12px;
  paint-order: stroke;
}

The stroke is painted first, and the fill is painted over its inner portion. This can make the visible outline appear outside the filled area.

Painting Markers First

.path {
  paint-order: markers stroke fill;
}

Markers are painted before the stroke and fill. Where the components overlap, later components can cover earlier ones.

Omitted Components

.shape {
  paint-order: stroke;
}

Because fill and markers are omitted, they are appended after stroke in their default relative order. The resulting sequence is stroke, fill, markers.

Important Distinction

The property changes the painting order of components within an element. It does not change the stacking order of separate elements or replace z-index.

Fill, Stroke, and Marker Painting Order

The three painting components serve different purposes in SVG graphics and text rendering.

Component Purpose
fill Paints the interior of a shape or the filled portion of text glyphs.
stroke Paints the outline of a shape or text glyphs.
markers Paints SVG marker graphics, such as arrowheads attached to paths.

Default Sequence

.shape {
  paint-order: normal;
}

The default sequence is fill, stroke, markers.

Stroke Before Fill

.shape {
  paint-order: stroke fill;
}

The stroke is drawn before the fill, which can cover the inner portion of the stroke.

Markers Before Stroke

.path {
  paint-order: markers stroke;
}

The full sequence becomes markers, stroke, fill.

Fill Before Markers

.path {
  paint-order: fill markers;
}

The full sequence becomes fill, markers, stroke.

All Three Components

.path {
  paint-order: stroke markers fill;
}

All three components are painted in the specified order.

Important Consideration

Changing the painting order does not automatically create a fill, stroke, or marker. Those components must be defined for the element.

Using paint-order With SVG Shapes

SVG shapes are a common use for paint-order, particularly when a thick stroke overlaps the filled area.

Basic SVG Circle

<svg viewBox="0 0 160 160" width="160" height="160" xmlns="http://www.w3.org/2000/svg">
  <circle class="circle-shape" cx="80" cy="80" r="50" />
</svg>
.circle-shape {
  fill: #60a5fa;
  stroke: #1e3a8a;
  stroke-width: 20px;
  paint-order: stroke;
}

The fill is painted over the inner portion of the stroke, preserving more of the visible fill area.

SVG Rectangle

<svg viewBox="0 0 200 120" width="200" height="120" xmlns="http://www.w3.org/2000/svg">
  <rect class="rectangle-shape" x="20" y="20" width="160" height="80" />
</svg>
.rectangle-shape {
  fill: #a7f3d0;
  stroke: #047857;
  stroke-width: 14px;
  paint-order: stroke fill;
}

The rectangle's fill covers the inside portion of its stroke.

Using a Shared SVG Class

.outlined-shape {
  stroke: #1f2937;
  stroke-width: 8px;
  paint-order: stroke;
}

The same class can be applied to multiple SVG shapes to maintain a consistent outline appearance.

Inherited Painting Order

svg {
  paint-order: stroke;
}

Because paint-order is inherited, SVG descendants can use this painting order unless they specify their own value.

Using paint-order With Text

The paint-order property can change how text fill and stroke overlap. This is useful for headings, labels, and decorative outlined text.

Default Text Stroke

.outlined-heading {
  color: #ffffff;
  -webkit-text-stroke: 4px #1e3a8a;
  paint-order: normal;
}

The stroke is painted over the text fill, potentially covering part of the letter shapes.

Stroke Behind Text Fill

.outlined-heading {
  color: #ffffff;
  -webkit-text-stroke: 4px #1e3a8a;
  paint-order: stroke fill;
}

The fill is painted over the inner portion of the stroke, helping preserve the letter shapes.

Thicker Outlined Text

.display-heading {
  color: #fef3c7;
  -webkit-text-stroke: 6px #92400e;
  paint-order: stroke;
}

Painting the stroke first can produce a more readable result when a thick outline is used.

Text Without a Stroke

.plain-heading {
  color: #2563eb;
  paint-order: stroke;
}

If no visible stroke is defined, changing the painting order may produce no visible difference.

Browser Considerations

Text stroke support and rendering can vary across browsers. Test outlined text carefully, particularly when using thick strokes or small font sizes.

Controlling SVG Markers

SVG markers are reusable graphics attached to points along paths, such as arrowheads at the ends of lines.

Basic Marker Example

<svg viewBox="0 0 300 100" width="300" height="100" xmlns="http://www.w3.org/2000/svg">
  <defs>
    <marker id="arrow" markerWidth="10" markerHeight="10" refX="8" refY="3" orient="auto">
      <path d="M0,0 L0,6 L9,3 z" fill="#2563eb" />
    </marker>
  </defs>
  <path class="arrow-line" d="M20,50 L270,50" marker-end="url(#arrow)" />
</svg>
.arrow-line {
  fill: none;
  stroke: #1e3a8a;
  stroke-width: 8px;
  paint-order: markers stroke;
}

The marker is painted before the path's stroke. Where they overlap, the stroke can cover part of the marker.

Painting Markers Last

.arrow-line {
  paint-order: normal;
}

The default painting order places markers after the fill and stroke, so they appear above those components where they overlap.

Painting Markers First

.arrow-line {
  paint-order: markers;
}

The markers are painted before the fill and stroke.

Important Consideration

The markers keyword controls the painting order of SVG marker graphics. It does not refer to HTML list markers such as those created by ::marker.

paint-order Example

The following example compares the default painting order with a stroke-first painting order on two SVG circles.

HTML Example

<div class="paint-demo">
  <div class="paint-item">
    <h3>Normal Painting Order</h3>
    <svg viewBox="0 0 160 160" width="160" height="160" xmlns="http://www.w3.org/2000/svg">
      <circle class="normal-circle" cx="80" cy="80" r="50" />
    </svg>
    <p>paint-order: normal;</p>
  </div>
  <div class="paint-item">
    <h3>Stroke First</h3>
    <svg viewBox="0 0 160 160" width="160" height="160" xmlns="http://www.w3.org/2000/svg">
      <circle class="stroke-first-circle" cx="80" cy="80" r="50" />
    </svg>
    <p>paint-order: stroke;</p>
  </div>
</div>

CSS Example

.paint-demo {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
}
.paint-item {
  flex: 1 1 180px;
  text-align: center;
}
.paint-item h3 {
  font-size: 16px;
}
.paint-item circle {
  fill: #60a5fa;
  stroke: #1e3a8a;
  stroke-width: 24px;
}
.normal-circle {
  paint-order: normal;
}
.stroke-first-circle {
  paint-order: stroke;
}
Browser Result

Normal Painting Order

paint-order: normal;

Stroke First

paint-order: stroke;

With paint-order: normal, the stroke covers part of the fill. With paint-order: stroke, the fill covers the inner portion of the stroke, leaving more of the blue interior visible.

Practical Text Outline Example

.outlined-title {
  color: #ffffff;
  -webkit-text-stroke: 5px #1e3a8a;
  paint-order: stroke fill;
  font-weight: 700;
}

This paints the text stroke behind the fill, helping keep the letters readable while maintaining a strong outline.

Accessibility Considerations

The paint-order property changes visual rendering but does not change the meaning or accessibility structure of text and SVG graphics.

Maintain Text Readability

Outlined text should remain legible at different font sizes. Avoid strokes that obscure letter shapes or reduce readability.

Preserve Sufficient Contrast

Choose fill and stroke colors that provide sufficient contrast against the background. Painting order alone does not guarantee accessible contrast.

Provide Accessible SVG Names

<svg role="img" aria-label="Quarterly sales indicator" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
  <circle cx="50" cy="50" r="35" fill="#60a5fa" stroke="#1e3a8a" stroke-width="8" />
</svg>

Meaningful SVG graphics should have an accessible name or appropriate alternative text. Decorative SVG graphics can be hidden from assistive technology when suitable.

Do Not Rely on Color Alone

If a graphic communicates information, provide labels, text, or other visual cues rather than relying only on fill and stroke colors.

Test at Different Sizes

Thick strokes can reduce the visible interior of small shapes and text. Test graphics at the sizes used in the final layout.

Important Consideration

The paint-order property does not affect keyboard navigation, document reading order, or semantic HTML structure.

Common Mistakes

Using reverse

.shape {
  paint-order: reverse;
}

The reverse keyword is invalid. Specify the desired component order explicitly.

Repeating a Component

.shape {
  paint-order: stroke stroke fill;
}

Each painting component can appear only once.

Using Commas

.shape {
  paint-order: stroke, fill;
}

Painting components must be separated by spaces, not commas.

Expecting a Stroke to Appear Automatically

.shape {
  paint-order: stroke;
}

Changing the painting order does not create a visible stroke. Define a stroke and an appropriate stroke width when needed.

Confusing paint-order With z-index

paint-order controls the fill, stroke, and markers of an individual element. It does not control the stacking order of separate elements.

Confusing SVG Markers With List Markers

The markers value refers to SVG marker graphics, not HTML list bullets or the ::marker pseudo-element.

Using Numeric Values

.shape {
  paint-order: 1 2 3;
}

The property accepts painting component keywords, not numbers.

Ignoring Inheritance

The property is inherited. A painting order applied to a parent can affect descendant text or SVG graphics unless overridden.

Assuming Every Element Has Markers

The markers component has no visible effect when the element does not use SVG markers.

Important Considerations

Keep the following points in mind when using paint-order:

  • It controls the painting order of fill, stroke, and markers.
  • Its initial value is normal.
  • The property is inherited.
  • The default painting order is fill, stroke, markers.
  • The stroke value paints the stroke before the fill and markers.
  • The fill value paints the fill first.
  • The markers value paints SVG markers first.
  • One, two, or three painting components can be specified.
  • Omitted components are appended in their default relative order.
  • Each component can appear only once.
  • Painting components are separated by spaces, not commas.
  • The property does not accept numeric values.
  • It is commonly used with SVG shapes and paths.
  • It can also affect text fill and stroke rendering.
  • Painting the stroke first can preserve more of the visible fill area.
  • The property does not create a fill, stroke, or marker.
  • SVG markers must be defined separately.
  • The markers keyword does not refer to HTML list markers.
  • The property does not change the stacking order of separate elements.
  • It does not replace z-index.
  • Changing painting order does not affect the geometry of a shape.
  • Painting order can influence the visual appearance of thick outlines.
  • Text and SVG graphics should remain readable at different sizes.
  • Meaningful SVG graphics should have accessible names or text alternatives.
  • Browser rendering should be tested when using text strokes or complex SVG markers.

Browser Support

The CSS paint-order property is Widely available in modern browsers, including Chrome, Edge, Firefox, and Safari.

Support for SVG painting order is well established. Text stroke rendering and other related features may vary across browsers, so complex outlined text and SVG graphics should be tested in the intended browsers.

For current compatibility information, visit Can I Use? and search for paint-order.

Specifications

The paint-order property is defined in the CSS Fill and Stroke Module Level 3 specification.

CSS Fill and Stroke Module Level 3

The specification defines the painting order of fill, stroke, and marker components for text and SVG graphics.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: paint-order