SVG <text>

SVG Text - <text>

<text> elements are used to define text.

Example 1

Write a text:

I love SVG!

This is the SVG code:

<svg height="30" width="200">
  <text x="0" y="15" fill="red">I love SVG!</text>
</svg>

Try It Yourself

Example 2

Rotated text:

I love SVG

This is the SVG code:

<svg height="60" width="200">
  <text x="0" y="15" fill="red" transform="rotate(30 20,40)">I love SVG</text>
</svg>

Try It Yourself

Example 3

<text> element can be combined with <tspan> elements together, are arranged in any number of subgroups. Each <tspan> elements can contain different formats and positions.

Multi-line text (using <tspan> element):

Several lines: First line. Second line.

This is the SVG code:

<svg height="90" width="200">
  <text x="10" y="20" style="fill:red;">Several lines:</text>
    <tspan x="10" y="45">First line.</tspan>
    <tspan x="10" y="70">Second line.</tspan>
  </text>
</svg>

Try It Yourself

Example 4

As link text (with <a> element):

I love SVG!

This is the SVG code:

<svg height="30" width="200" xmlns:xlink="http://www.w3.org/1999/xlink">
  <a xlink:href="www.codew3c.com/graphics/index.asp" target="_blank">
    <text x="0" y="15" fill="red">I love SVG!</text>
  </a>
</svg>

Try It Yourself