L'élément SVG text définit un élément graphique contenant du texte. Notez qu'il est possible d'y appliquer un dégradé, un motif, un tracé spécifique (clipping path), un masque ou un filtre.
Si du texte est écrit dans le SVG sans être intégré dans un balise <text>, il ne sera pas affiché. Le texte n'est pas caché par défaut, la propriété display ne le montre simplement pas.
<?xml version="1.0"?><svgxmlns="http://www.w3.org/2000/svg"width="100px"height="30px"viewBox="0 0 1000 300"><textx="250"y="150"font-family="Verdana"font-size="55">
Bonjour tout le monde!
</text><!-- Dessine le contour de l'image --><rectx="1"y="1"width="998"height="298"fill="none"stroke-width="2"/></svg>
L'élément <text> est utilisé pour dessiner des caractères de texte. L'exemple de code suivant écrit un text svg à l'aide de coordonnées x/y.
xml
<svgxmlns="http://www.w3.org/2000/svg"width="100px"height="50px"><textx="10"y="20">SVG Text Example</text></svg>
Le texte en SVG peut être pivoté. L'exemple de code suivant démontre la rotation de texte à l'aide de l'attribut transform.
xml
<svgxmlns="http://www.w3.org/2000/svg"width="100px"height="50px"><textx="10"y="20"transform="rotate(30 20,40)">
SVG Text Rotation example
</text></svg>
Le texte SVG peut également être stylisé avec du CSS contenant les propriétés SVG.
xml
<svgxmlns="http://www.w3.org/2000/svg"width="100px"height="50px"><textx="10"y="20"style="font-family: Times New Roman;font-size: 24;stroke: #00ff00;fill: #0000ff;">
SVG text styling
</text></svg>
Tip: you can click/tap on a cell for more information.
Full support
Full support
No support
No support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.