Latest web development tutorials

SVG text

SVG Text - <text>

<Text> element is used to define the text.


Example 1

Write a text:

Here is the SVG Code:

Examples

<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
<text x="0" y="15" fill="red">I love SVG</text>
</svg>

try it"

For Opera users: view SVG file (right-click on the preview source SVG graphics).


Example 2

Rotated text:

Here is the SVG Code:

Examples

<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
<text x="0" y="15" fill="red" transform="rotate(30 20,40)">I love SVG</text>
</svg>

try it"

For Opera users: view SVG file (right-click on the preview source SVG graphics).


Example 3

Text path:

Here is the SVG Code:

Examples

<svg xmlns="http://www.w3.org/2000/svg" version="1.1"
xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<path id="path1" d="M75,20 a1,1 0 0,0 100,0" />
</defs>
<text x="10" y="100" style="fill:red;">
<textPath xlink:href="#path1">I love SVG I love SVG</textPath>
</text>
</svg>

try it"

For Opera users: view SVG file (right-click on the preview source SVG graphics).


Example 4

Any number of sub-group elements and <tspan> element can be arranged. Each <tspan> element can contain different formats and locations. A few lines of text (with <tspan> element):

Here is the SVG Code:

Examples

<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
<text x="10" y="20" style="fill:red;">Several lines:
<tspan x="10" y="45">First line</tspan>
<tspan x="10" y="70">Second line</tspan>
</text>
</svg>

try it"

For Opera users: view SVG file (right-click on the preview source SVG graphics).


Example 5

As the link text (<a> element):

Here is the SVG Code:

Examples

<svg xmlns="http://www.w3.org/2000/svg" version="1.1"
xmlns:xlink="http://www.w3.org/1999/xlink">
<a xlink:href="http://www.w3schools.com/svg/" target="_blank">
<text x="0" y="15" fill="red">I love SVG</text>
</a>
</svg>

try it"

For Opera users: view SVG file (right-click on the preview source SVG graphics).