Fill and Stroke
The fill and stroke attribute lets you color shapes.
Fill SVG attributes
fill
Sets the interior color of an object. Specify:
none— transparent fill- a color — e.g.
red,#ff0000,rgba(255,0,0,1) - a URL — e.g.
url(#my-gradient),
fill-opacity
Sets the fill opacity. Specify something like 0.5 or 50%.
fill-rule
Specify how to decide the "inside part" of the shape.
nonzero— color anything "inside" the shape*evenodd— color anything "inside" the shape; but parts of the shape that are crossed even number of times by the path are considered "outside" (it's "cancelled out")**
(*) Mathematically, you test the "insideness" of a point in the shape by drawing a ray from that point to infinity in any direction, then counting how many segments of the path crosses the ray. By nonzero rule, if there is at least one path segment crossing the ray, it's considered "inside", otherwise it's considered "outside"
(**) Similar as above. With evenodd rule, if there is an odd amount of path segments crossing the ray, it's considered "inside", otherwise it's considered "outside"
Stroke SVG attributes
stroke
Sets the outline color of the shape.
none— no stroke- a color — e.g.
red,#ff0000,rgba(255,0,0,1) - a URL — e.g.
url(#my-gradient),
stroke-width
Sets the width of the stroke. Specify a number or a percentage (relative to the size of the view).
stroke-opacity
Sets the opacity of the stroke. Specify something like 0.5 or 50%.
stroke-linecap
Sets the shape at the end of open paths ("the caps"). Specify butt, round, or square.
stroke-linejoin
Defines the shape to be used at the path corners. Specify miter, round, bevel, or arcs.
stroke-linejoin (Source: SVGWG)stroke-dasharray
Defines the pattern of dashes and gaps in the path. Specify space/comma separated array of numbers/percentages, e.g. 10 1 4 1. If you specify an odd number of values, it will be repeated to yield an even number of values: i.e. 5 3 2 is equivalent to 5 3 2 5 3 2.
You can combine this with pathLength to control the number of repetitions along the path.
stroke-dashoffset
Offsets the rendering of stroke-dasharray.
Specify a number or a percentage (percentage of the current viewport).
Other SVG attributes
opacity
Sets the opacity of an object. Specify a number from 0 to 1.
References
- Fills and Strokes (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Fills_and_Strokes
- fill (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/fill
- Chapter 13: Painting: Filling, Stroking and Marker Symbols » 13.4.1. Specifying fill paint: the ‘fill’ property (SVGWG) — https://svgwg.org/svg2-draft/painting.html#FillProperty
- Chapter 13: Painting: Filling, Stroking and Marker Symbols » 13.5.5. Controlling line joins: the ‘stroke-linejoin’ and ‘stroke-miterlimit’ properties (SVGWG) — https://svgwg.org/svg2-draft/painting.html#StrokeLinejoinProperty
- fill-rule (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/fill-rule
- stroke (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke
- stroke-linecap (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-linecap
- stroke-linejoin (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-linejoin
- stroke-dasharray (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dasharray
- stroke-dashoffset (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dashoffset