We have seen in the introducing example that the text
element can be used to put arbitrary text in SVG documents:
<text x="10" y="10">Hello World!</text>
The x
and y
attributes determine where in the viewport the text will appear. The attribute text-anchor
, which can have the values "start"
, "middle"
, "end"
or "inherit"
, decides in which direction the text flows from this point. The attribute dominant-baseline
decides the vertical alignment.
Like with the shape elements, text can be colorized with the fill
attribute and given a stroke with the stroke
attribute. Both may also refer to gradients or patterns, which makes simple coloring text in SVG very powerful compared to CSS 2.1.