CSS Reference ยท Properties for Special Contexts
The fill property
Reference for the CSS fill property: paint the inside of SVG shapes and text with colors, gradients, patterns or currentColor, with syntax and examples.
The fill property sets the paint used for the inside of an SVG shape or SVG text. The paint can be a color, a reference to a gradient or pattern, or none to leave the inside transparent.
It is the SVG counterpart of background-color, but it follows the actual outline of the shape rather than a rectangle.
circle { fill: tomato; }
Try it
Syntax
fill: none | <color> | <url> [none | <color>]? | context-fill | context-stroke;
- Initial value:
black - Applies to: SVG shapes and text content elements
- Inherited: yes
- Animatable: yes (colors interpolate)
- Computed value:
none, a computed color, or a URL reference with an optional fallback
Values
| Value | Description |
|---|---|
<color> |
Any CSS color: names, hex, rgb(), hsl(), modern color functions. |
none |
No fill. The inside is transparent. |
url(#id) |
Paints with a gradient or pattern defined in the SVG. A fallback color may follow the URL and is used if the reference fails. |
currentColor |
Uses the element's CSS color, so icons match surrounding text. |
context-fill, context-stroke |
Reuse the fill or stroke of the context element, mainly useful in markers and <use>; support varies, so check a compatibility table. |
Usage notes
- Open paths still fill. Even an unclosed
<path>is filled as if it were closed. Usefill: nonefor lines. - Fill vs transparency. To make the fill see-through without changing the stroke, use a color with alpha or
fill-opacity.opacityaffects the whole element. fill-rule. For self-crossing or nested paths,fill-rule(nonzeroorevenodd) decides which regions count as inside.- Inherited. Setting
fillon<svg>or<g>themes everything beneath it unless a child sets its own. - Not for HTML. On ordinary HTML elements
fillhas no effect; usebackgroundorcolor. - Accessibility. Do not rely on fill color alone to convey meaning; add text, patterns or shape differences.
Browser support
Supported in every major browser for SVG; context-fill and context-stroke are less widely supported, so check a compatibility table first.
Related
strokepaint-order- SVG properties in CSS
- Lesson: SVG