SVG <texte>


Texte SVG - <texte>

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


Exemple 1

Rédigez un texte :

I love SVG! Sorry, your browser does not support inline SVG.

Voici le code SVG :

Exemple

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

Exemple 2

Faites pivoter le texte :

I love SVG Sorry, your browser does not support inline SVG.

Voici le code SVG :

Exemple

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


Exemple 3

L'élément <text> peut être arrangé en n'importe quel nombre de sous-groupes avec l'élément <tspan>. Chaque élément <tspan> peut contenir une mise en forme et une position différentes.

Texte sur plusieurs lignes (avec l'élément <tspan>) :

Several lines: First line. Second line. Sorry, your browser does not support inline SVG.

Voici le code SVG :

Exemple

<svg height="90" width="200">
  <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>

Exemple 4

Texte sous forme de lien (avec l'élément <a>) :

I love SVG! Sorry, your browser does not support inline SVG.

Voici le code SVG :

Exemple

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