<path> elements, <text> elements and basic shapes can be filled (which means painting the interior of the object) and stroked (which means painting along the outline of the object). Filling and stroking both can be thought of in more general terms as painting operations.
Certain elements (i.e., <path>, <polyline>, <polygon> and <line> elements) can also have marker symbols drawn at their vertices.
With SVG, you can paint (i.e., fill or stroke) with:
SVG uses the general notion of a paint server. Gradients and patterns are just specific types of paint servers. For example, first you define a gradient by including a <gradient> element within a <defs>, assign an ID to that <gradient> object, and then reference that ID in a 'fill' or 'stroke' property:
<?xml version="1.0" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG August 1999//EN" "http://www.w3.org/Graphics/SVG/SVG-19990812.dtd"> <svg width="4in" height="3in"> <desc>Linear gradient example </desc> <g> <defs> <linearGradient id="MyGradient"> <stop offset="0%" style="color:#F60"/> <stop offset="70%" style="color:#FF6"/> </linearGradient> </defs> <rect style="fill: url(#MyGradient)" width="20" height="15.8"/> </g> </svg>
Value: | none | currentColor | <color> [icc-color(<colorvalue>*)] | inherit | <uri> [ none | currentColor | <color> [icc-color(<colorvalue>*)] | inherit ] |
Initial: | currentColor |
Applies to: | all elements |
Inherited: | see Inheritance of Painting Properties below |
Percentages: | N/A |
Media: | visual |
Note that graphical objects that are not closed (e.g., a <path> without a closepath at the end or a <polyline>) still can be filled. The fill operation automatically closes all open subpaths by connecting the last point of the subpath with the first point of the subpath before painting the fill.
Value: | evenodd | nonzero | inherit |
Initial: | evenodd |
Applies to: | all elements |
Inherited: | yes |
Percentages: | N/A |
Media: | visual |
Value: | <opacity-value> |
Initial: | 100% |
Applies to: | all elements |
Inherited: | yes |
Percentages: | Allowed |
Media: | visual |
'fill-opacity' specifies the opacity of the painting operation used to fill the current object. It is important to note that any given object can have three different opacity properties: 'fill-opacity', 'stroke-opacity' and 'opacity'. The 'fill' painting operation is done and blended into the current background (or temporary offscreen buffer, if 'opacity' is not 1.0) using the value of 'fill-opacity'. Next, The 'stroke' painting operation is done and blended into the current background (or temporary offscreen buffer, if 'opacity' is not 1.0) using the value of 'stroke-opacity'. Finally, if 'opacity' is not 1.0, the offscreen holding the object as a whole is blended into the current background.
(The above paragraph needs to be moved someplace else, such as SVG Rendering Model.)
Value: | none | currentColor | <color> [icc-color(<number>*)] | inherit | <uri> [ none | currentColor | <color> | inherit ] |
Initial: | none |
Applies to: | all elements |
Inherited: | see Inheritance of Painting Properties below |
Percentages: | N/A |
Media: | visual |
Value: | <width> | inherit |
Initial: | 1 |
Applies to: | all elements |
Inherited: | yes |
Percentages: | Yes |
Media: | visual |
Value: | butt | round | square | inherit |
Initial: | butt |
Applies to: | all elements |
Inherited: | yes |
Percentages: | N/A |
Media: | visual |
'stroke-linecap' specifies the shape to be used at the end of open subpaths when they are stroked.
Value: | miter | round | bevel | inherit |
Initial: | miter |
Applies to: | all elements |
Inherited: | yes |
Percentages: | N/A |
Media: | visual |
'stroke-linejoin' specifies the shape to be used at the corners of paths (or other vector shapes) that are stroked. when they are stroked.
Value: | <miterlimit> | inherit |
Initial: | 8 |
Applies to: | all elements |
Inherited: | yes |
Percentages: | N/A |
Media: | visual |
When two line segments meet at a sharp angle and miter joins have been specified for 'stroke-linejoin', it is possible for the miter to extend far beyond the thickness of the line stroking the path. The 'stroke-miterlimit' imposes a limit on the ratio of the miter length to the 'stroke-linewidth'.
Value: | none | <dasharray> | inherit |
Initial: | none |
Applies to: | all elements |
Inherited: | yes |
Percentages: | Yes. See below. |
Media: | visual |
'stroke-dasharray' controls the pattern of dashes and gaps used to stroke paths. <dasharray> should contain a list of space- or comma-separated numbers that specify the lengths of alternating dashes and gaps in user units. If an odd number of values is provided, then the list of values is repeated to yield an even number of values. Thus, stroke-dasharray: 5 3 2 is equivalent to stroke-dasharray: 5 3 2 5 3 2.
Value: | <dashoffset> | inherit |
Initial: | 0 |
Applies to: | all elements |
Inherited: | yes |
Percentages: | Yes. See below. |
Media: | visual |
'stroke-dashoffset' specifies the distance into the dash pattern to start the dash.
Value: | <opacity-value> | inherit |
Initial: | 100% |
Applies to: | all elements |
Inherited: | yes |
Percentages: | Allowed |
Media: | visual |
'stroke-opacity' specifies the opacity of the painting operation used to stroke the current object. (??? Add link about how different opacity parameters interact.)
To use a marker symbol for arrowheads or polymarkers, you need to define a <marker> element which defines the marker symbol and then refer to that <marker> element using the various marker properties (i.e., 'marker-start', 'marker-end', 'marker-mid' or 'marker') on the given <path> element or vector graphic shape. Here is an example which draws a triangular marker symbol that is drawn as an arrowhead at the end of a path:
<?xml version="1.0" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG August 1999//EN" "http://www.w3.org/Graphics/SVG/SVG-19990812.dtd"> <svg width="4in" height="4in" viewBox="0 0 4000 4000" > <defs> <marker id="Triangle" viewBox="0 0 10 10" refX="0" refY="5" markerWidth="1.25" markerHeight="1.75" orient="auto"> <path d="M 0 0 L 10 5 L 0 10 z" /> </marker> </defs> <desc>Placing an arrowhead at the end of a path. </desc> <path d="M 1000 1000 L 2000 1000 L 3000 2000" style="fill:none; stroke:black; stroke-width:100; marker-end:url(#Triangle)" /> </svg>
The <marker> element defines the graphics that is to be
used for drawing arrowheads or polymarkers on a given
<path> element or vector graphic shape.
<!ELEMENT marker (defs?,desc?,title?, (path|text|rect|circle|ellipse|line|polyline|polygon| use|image|svg|g|switch|a| animate|animateTransform|animateColor)*)> <!ATTLIST marker id ID #IMPLIED xml:lang NMTOKEN #IMPLIED xml:space (default|preserve) #IMPLIED class NMTOKENS #IMPLIED style CDATA #IMPLIED refX CDATA #IMPLIED refY CDATA #IMPLIED viewBox CDATA #IMPLIED preserveAspectRatio CDATA 'xMidYMid meet' markerUnits (stroke-width | userSpace) "stroke-width" markerWidth CDATA "3" markerHeight CDATA "3" orient CDATA "0"> |
Attribute definitions:
Markers are drawn such that their reference point (i.e., attributes ref-x and ref-y) is positioned at the given vertex.
'marker-start' defines the arrowhead or polymarker that should be drawn at the first vertex of the given <path> element or vector graphic shape. 'marker-end' defines the arrowhead or polymarker that should be drawn at the final vertex. 'marker-mid' defines the arrowhead or polymarker that should be drawn at every other vertex (i.e., every vertex except the first and last).
Value: | none | inherit | <uri> |
Initial: | none |
Applies to: | all elements |
Inherited: | see Inheritance of Painting Properties below |
Percentages: | N/A |
Media: | visual |
The 'marker' property specifies the marker symbol that should be used for all points on the sets the value for all vertices on the given <path> element or vector graphic shape. It is a short-hand for the three individual marker properties:
Value: | see individual properties |
Initial: | see individual properties |
Applies to: | all elements |
Inherited: | see Inheritance of Painting Properties below |
Percentages: | N/A |
Media: | visual |
The following provides details on how markers are rendered:
For illustrative purposes, we'll repeat the marker example shown earlier:
<?xml version="1.0" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG August 1999//EN" "http://www.w3.org/Graphics/SVG/SVG-19990812.dtd"> <svg width="4in" height="4in" viewBox="0 0 4000 4000" > <defs> <marker id="Triangle" viewBox="0 0 10 10" refX="0" refY="5" markerWidth="1.25" markerHeight="1.75" orient="auto"> <path d="M 0 0 L 10 5 L 0 10 z" /> </marker> </defs> <desc>Placing an arrowhead at the end of a path. </desc> <path d="M 1000 1000 L 2000 1000 L 3000 2000" style="fill:none; stroke:black; stroke-width:100; marker-end:url(#Triangle)" /> </svg></svg>
The rendering effect of the above file will be visually identical to the following:
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG August 1999//EN"
"http://www.w3.org/Graphics/SVG/SVG-19990812.dtd">
<svg width="4in" height="4in"
viewBox="0 0 4000 4000" >
<defs>
<!-- Note: to illustrate the effect of "marker",
replace "marker" with "symbol" and remove the various
marker-specific attributes -->
<symbol id="Triangle"
viewBox="0 0 10 10" refX="0" refY="5">
<path d="M 0 0 L 10 5 L 0 10 z" />
</symbol>
</defs>
<desc>File which produces the same effect
as the marker example file, but without
using markers.
</desc>
<!-- The path draws as before, but without the marker properties -->
<path d="M 1000 1000 L 2000 1000 L 3000 2000"
style="fill:none; stroke:black; stroke-width:100" />
<!-- The following logic simulates drawing a marker
at final vertex of the path. -->
<!-- First off, move the origin of the user coordinate system
so that the origin is now aligned with the end point of the path. -->
<g transform="translate(3000 2000)" >
<!-- Now, rotate the coordinate system 45 degrees because
the marker specified orient="auto" and the final segment
of the path is going in the direction of 45 degrees. -->
<g transform="rotate(45)" >
<!-- Establish a new viewport with an <svg> element.
The width/height of the viewport are 1.25 and 1.75 times
the current stroke-width, respectively. Since the
current stroke-width is 100, the viewport's width/height
is 125 by 175. Apply the viewBox attribute
from the <marker> element onto this <svg> element.
Transform the marker symbol to align (refX,refY) with
the origin of the viewport. -->
<svg width="125" height="175"
viewBox="0 0 10 10"
transform="translate(0,-5)" >
<!-- Expand out the contents of the <marker> element. -->
<path d="M 0 0 L 10 5 L 0 10 z" />
</svg>
</g>
</g>
</svg>
The creator of an SVG document might want to provide a hint to the implementation about what tradeoffs to make as it renders vector graphics elements such as <path> elements and basic shapes such as circles and rectangles. The 'shape-rendering' property provides these hints.
Value: | default | optimizeSpeed | crispEdges | geometricPrecision | inherit |
Initial: | false |
Applies to: | all elements |
Inherited: | yes |
Percentages: | N/A |
Media: | visual |
The creator of an SVG document might want to provide a hint to the implementation about what tradeoffs to make as it renders text. The 'text-rendering' property provides these hints.
Value: | default | optimizeSpeed | optimizeLegibility | geometricPrecision | inherit |
Initial: | default |
Applies to: | <text> elements |
Inherited: | yes |
Percentages: | yes |
Media: | visual |
The creator of an SVG document might want to provide a hint to the implementation about how to make speed vs. quality tradeoffs as it performs image processing. The 'image-rendering' property provides a hint to the SVG user agent about how to optimize its image rendering.:
Value: | default | optimizeSpeed | optimizeQuality | inherit |
Initial: | default |
Applies to: | images |
Inherited: | yes |
Percentages: | N/A |
Media: | visual |
The 'visibility' indicates whether a given object should be rendered at all.
Value: | visible | hidden | inherit |
Initial: | visible |
Applies to: | all elements |
Inherited: | yes |
Percentages: | N/A |
Media: | visual |
The values of any of the painting properties described in this chapter can be inherited from a given object's parent. Painting, however, is always done on each leaf-node individually, never at the <g> level. Thus, for the following SVG, two distinct gradients are painted (one for each rectangle):
<?xml version="1.0" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG August 1999//EN" "http://www.w3.org/Graphics/SVG/SVG-19990812.dtd"> <svg width="4in" height="3in"> <desc>Gradients apply to leaf nodes </desc> <g> <defs> <linearGradient id="MyGradient"> <stop offset="0%" style="color:#F60"/> <stop offset="70%" style="color:#FF6"/> </linearGradient> </defs> <g style="fill: url(#MyGradient)"> <rect width="20" height="15.8"/> <rect width="35" height="8"/> </g> </g> </svg>