SVG <text>

Texte SVG - <text>

<text> L'élément est utilisé pour définir le texte.

Exemple 1

Écrivez un texte :

Je aime SVG!

Voici le code SVG :

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

Essayez-le vous-même

Exemple 2

Rotation du texte :

Je aime SVG

Voici le code SVG :

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

Essayez-le vous-même

Exemple 3

<text> élément peut être <tspan> éléments ensemble, ils sont organisés en un nombre illimité de sous-groupes. Chaque <tspan> Les éléments peuvent contenir différents formats et positions.

Texte multiligne (utilisez l'élément <tspan>) :

Plusieurs lignes : Première ligne. Deuxième ligne.

Voici le code SVG :

<svg height="90" width="200">
  <text x="10" y="20" style="fill:red;">Plusieurs lignes :
    <tspan x="10" y="45">Première ligne.</tspan>
    <tspan x="10" y="70">Deuxième ligne.</tspan>
  </text>
</svg>

Essayez-le vous-même

Exemple 4

comme texte de lien (avec <a> élément) :

Je aime SVG!

Voici le code SVG :

<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">Je aime SVG!</text>
  </a>
</svg>

Essayez-le vous-même