-
CSS > le style pour le svg
CSS
circle { stroke: #000066; fill: #0000cc; } circle.vert { stroke: #006600; fill: #00cc00; } circle.rouge{ stroke: #660000; fill: #cc0000; }
path
fillcouleur de remplissagefill-opacityopacité du remplissagefill-rulefill rule of the shapemarkerSets marker used along the lines (edges) of this shape.marker-startSets start marker used along the lines (edges) of this shape.marker-midSets mid marker used along the lines (edges) of this shape.marker-endSets end marker used along the lines (edges) of this shape.strokecouleur du contourstroke-dasharraySets the stroke (line) dashing du contourstroke-dashoffsetSets the stroke (line) dash offset du contourstroke-linecapSets the stroke (line) line cap du contour (round, butt et square)stroke-linejoinarrondi des jointures (miter, round et bevel)stroke-miterlimitSets the stroke (line) miter limit du contourstroke-opacityopacité du contourstroke-widthépaisseur du contourtext-renderingSets the text-rendering du contourStroke
stroke-linecap
butt square round
butt
cut off exactly where the line ends.square
results in a linecap that looks likebutt
(cut off), but which extends a bit beyond where the line ends.round
results in a round linecap.This example defines three green lines with a
stroke-width
of 10 to better illustrate the effect of thestroke-linecap
CSS property. Inside each green line is drawn a black line with astroke-width
of 1.This line has the same
x1, y1
andx2, y2
coordinates as the green line, but has nostroke-linecap
set.That way you can see the difference between the different
stroke-linecap
values.stroke-linejoin
The
stroke-linejoin
CSS property defines how the join between two lines in a shape is rendered. Thestroke-linejoin
CSS property can take one of three values. These values are:miter round bevel
Here are three SVG
stroke-linejoin
examples which illustrate these different values:<path d="M20,100 l20,-50 l20,50" style="stroke: #000000; fill:none; stroke-width:16px; stroke-linejoin: miter;" /> <text x="22" y="20">miter</text> <path d="M120,100 l20,-50 l20,50" style="stroke: #000000; fill:none; stroke-width:16px; stroke-linejoin: round;" /> <text x="122" y="20">round</text> <path d="M220,100 l20,-50 l20,50" style="stroke: #000000; fill:none; stroke-width:16px; stroke-linejoin: bevel;" /> <text x="222" y="20">bevel</text>
stroke-miterlimit
The
stroke-miterlimit
CSS propety is used together with thestroke-linejoin
CSS property. Ifstroke-linejoin
is set to miter, then thestroke-miterlimit
can be used to limit how far between the point where the two lines meet, that the line join (corner) extends.Here is an SVG
stroke-miterlimit
example:<path d="M20,100 l20,-50 l20,50" style="stroke: #000000; fill:none; stroke-width:16px; stroke-linejoin: miter; stroke-miterlimit: 1.0; " /> <text x="29" y="20">1.0</text> <path d="M120,100 l20,-50 l20,50" style="stroke: #000000; fill:none; stroke-width:16px; stroke-linejoin: miter; stroke-miterlimit: 2.0; " /> <text x="129" y="20">2.0</text> <path d="M220,100 l20,-50 l20,50" style="stroke: #000000; fill:none; stroke-width:16px; stroke-linejoin: miter; stroke-miterlimit: 4.0; " /> <text x="229" y="20">4.0</text>
Notice how three different
stroke-miterlimit
values are used for the three paths which otherwise look pretty much the same. Here is the resulting image:1.0 2.0 4.0
The length of the line join is called miter length. The miter length is measured from the inner corner of the line join to the tip of the line join. In this image the miter length is drawn in red ontop of the joined lines, and repeated again to the right of the joined lines:
As you can imagine, the wider the stroke is, and the sharper the angle between the joining lines, the longer the miter becomes.
The
stroke-miterlimit
actually sets the limit for the ratio between the miter length and stroke width. Thus, astroke-miterlimit
of 1.0 means that the miter length can be maximally 1 x stroke width. The miter is cut off beyond that. 1.0 is the smallest possible value forstroke-miterlimit
.Here are some examples using
1.0
asstroke-miterlimit
value, but with different angles of the joining lines:Notice how the part of the miter which is cut off is larger when the angle is larger. That is because the sharper angle naturally produces a longer miter.
stroke-dasharray + stroke-dashoffset
The SVG
stroke-dasharray
CSS property is used to make the stroke of an SVG shape rendered with dashed lines. The reason it is called a "dash array" is that you provide an array of numbers as value. The values define the length of dashes and spaces. Therefore you should provide an even number of numbers.Here is an SVG
stroke-dasharray
example:<line x1="20" y1="20" x2="120" y2="20" style="stroke: #000000; fill:none; stroke-width: 6px; stroke-dasharray: 10 5" />
This example defines a stroke that is dashed with the dashed parts being 10 pixels wide, and the space between the dashes being 5 pixels. Here is the resulting image:
Here are a few more examples with different dash and space width:
<line x1="20" y1="20" x2="120" y2="20" style="stroke: #000000; fill:none; stroke-width: 6px; stroke-dasharray: 10 5 5 5" /> <line x1="20" y1="40" x2="120" y2="40" style="stroke: #000000; fill:none; stroke-width: 6px; stroke-dasharray: 10 5 5 10" />
The first line starts with a dash width of 10, followed by a space of 5 pixels, then with a dash of 5 pixels, and then another space of 5 pixels. And then the pattern is repeated.
The second line starts with a dash width of 10, followed by a space of 5 pixels, then a dash of 5 pixels, and finally a space of 10 pixels.
Here is the resulting image:
The
stroke-dashoffset
is used to set how far into dash pattern to start the pattern. That way you can start the dashing from e.g. halfway into the pattern, and then repeat the pattern from there. Here is an SVGstroke-dashoffset
example:<line x1="20" y1="20" x2="170" y2="20" style="stroke: #000000; fill:none; stroke-width: 6px; stroke-dasharray: 10 5; stroke-dashoffset: 5;" />
This example sets
dash-offset
to 5 pixels, meaning the rendering of the dashed line will start 5 pixels into the dash pattern (not all browsers fully support this yet). Here is the resulting image:stroke-opacity
The SVG
stroke-opacity
CSS property is used to define the opacity of the outline of an SVG shape. Thestroke-opacity
takes a decimal number between 0 and 1. The closer to 0 the value is, the more transparent the stroke is. The closer to 1 the value is, the more opaque the stroke is. The defaultstroke-opacity
is 1, meaning the stroke is fully opaque.Here is an SVG
stroke-opacity
example which shows three lines with differentstroke-opacity
ontop of a text:<text x="22" y="40">Text Behind Shape</text> <path d="M20,40 l50,0" style="stroke: #00ff00;fill:none;stroke-width:16px;stroke-opacity: 0.3;" /> <path d="M80,40 l50,0" style="stroke: #00ff00;fill:none;stroke-width:16px;stroke-opacity: 0.7;" /> <path d="M140,40 l50,0" style="stroke: #00ff00;fill:none;stroke-width:16px;stroke-opacity: 1;" />
Here is the resulting image. Notice how the text is less and less visible through the different lines.
texte
alignment-baselineSets how the text is aligned to its x and y coordinatesbaseline-shiftSets the baseline shift used to render textdominant-baselineSets the dominant baselineglyph-orientation-horizontalhorizontal glyph orientationglyph-orientation-verticalvertical glyph orientationkerningespacement entre les lettresdégradé
stop-colorSets the stop color used in a stop element used in a gradientstop-opacitySets the stop opacity used in a stop element used in a gradient