Colors in SVG: Filling and Stroking

The fill property paints the inside of a shape, path, or text with color, and the stroke property outlines the shape, path, or text. Understanding how SVG paints an object is important, because you can then control how an object will render. SVG has a painting order that it uses to create and paint objects. Objects are painted in the order in which they appear in the code. If two objects intersect, the object that was painted last will appear on top of the one that was painted first.

For instance, in the code snippet:

<rect x="50" y="50" rx="20" ry="20" width="300" 
height="300" style="fill:navy; stroke:#666"/>

<circle cx="200" cy="200" r="50" style="fill:green"/>

the rectangle will appear under the circle. ...

Get SVG for Web Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.