CSS Portal

CSS fill Property

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
fill
CSS PropertyThis property is supported by all modern browsers.
Updated 1st January 2026

Description

The fill property controls the interior painting of vector shapes and text in SVG contexts (and of SVG elements embedded in HTML). It determines what paint is used to cover the inside area of geometry — this can be a solid color, a gradient, a pattern, or another paint server — and that paint is composited into the final rendered image. Conceptually, think of fill as the setting that governs "what's inside" a shape, separate from any outline or border treatment.

In the visual stacking of a shape, the fill is rendered beneath the outline, so its appearance interacts with the element’s stroke and how the two overlap and blend; for that relationship see stroke. Because fill can reference complex paint sources (for example gradients or pattern definitions in SVG), the visual result may depend on the referenced coordinate systems, transformations, and any referenced elements — the fill is often resolved at paint time rather than being a simple color assignment.

The property does not behave like many typical CSS properties in that it normally applies to SVG painting rather than box-model backgrounds; it isn’t inherited by default, but it commonly uses the current text color when the special currentColor value is used, linking its visual result to the element’s color property. In the cascade, a specified fill on an element overrides inherited or user-agent defaults for that element’s interior painting.

When you animate or transition fills, the renderer must interpolate between paint representations — simple color-to-color transitions are straightforward, while transitions between different paint types (for example, a solid color and a gradient) may be handled differently across implementations and sometimes result in discrete switches. Additionally, overall compositing and transparency that affect the final appearance of a fill can be influenced by the element’s and parent context’s opacity settings; see opacity for how a final composite transparency interacts with fills.

Definition

Initial value
black
Applies to
SVG shapes and text content elements
Inherited
yes
Computed value
as specified
Animatable
by computed value type
JavaScript syntax
object.style.fill

Syntax

fill: <paint> | inherit;

Values

  • <paint>can be a color value, url() for gradients or patterns, or the keyword none.
  • inheritmeans the element inherits the fill value from its parent.

Example

    <div class="wrap">
<h1>CSS fill property - SVG examples</h1>
<svg class="icon" viewBox="0 0 100 100" aria-hidden="true">
<defs>
<linearGradient id="myGradient" x1="0" x2="1">
<stop offset="0%" stop-color="#ff9a9e" />
<stop offset="100%" stop-color="#fad0c4" />
</linearGradient>
</defs>

<circle class="primary" cx="25" cy="50" r="20" />
<rect class="grad-filled" x="55" y="30" width="30" height="40" rx="6" />
<path class="current" d="M50 15 L85 85 L15 85 Z" />
</svg>

<p class="note">The circle uses a solid fill, the rectangle uses a gradient, the triangle uses fill: currentColor.</p>
</div>
    .wrap {
      font-family: Inter, Roboto, Arial, sans-serif;
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 12px;
      padding: 24px;
      background: #f7fafc;
      color: #2c3e50; /* used by fill: currentColor */
      max-width: 560px;
      margin: 0 auto;
    }

    h1 {
      font-size: 16px;
      margin: 0;
      color: #111827;
    }

    svg.icon {
      width: 320px;
      height: 160px;
      overflow: visible;
    }

    /* Solid color fill */
    .primary {
      fill: #e74c3c;
      transition: fill 200ms ease;
    }

    /* Fill using a gradient defined inside the SVG */
    .grad-filled {
      fill: url(#myGradient);
    }

    /* Fill inherits the current CSS color */
    .current {
      fill: currentColor;
      opacity: 0.95;
    }

    .note {
      margin: 0;
      font-size: 13px;
      color: #6b7280;
      text-align: center;
      max-width: 420px;
    }
Open in editor

Browser Support

The following information will show you the current browser support for the CSS fill property. Hover over a browser icon to see the version that first introduced support for this CSS property.

This property is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee