Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

SVG Text

SVG Text

In SVG, the The element is used to add text content to an SVG image; it lets you display text at a specified position and control the text style, font, size, etc. by setting attributes.

Basic Syntax



  y="y-coordinate"          

  font-family="font"        

  font-size="size"          

  fill="fill-color"         

  text-anchor="anchor"      

>

  Text content              



Attribute Analysis:

The following code draws a piece of text in an SVG image, with the text content "Hello, SVG!", font Arial, size 20 pixels, blue color, center-aligned, and the top-left corner of the text at (100, 100).



  Hello, SVG!



Example 1

Write a text:

Below is the SVG code:

Example

  I love SVG

Try it »

Click to view:View SVG File.


Example 2

Rotated text:

Below is the SVG code:

Example

  I love SVG

Try it »

Click to view:View SVG File.


Example 3

Text on a path:

Below is the SVG code:

Example

xmlns:xlink="http://www.w3.org/1999/xlink">

  

   

 

 

    I love SVG I love SVG

 

Try it »

Click to view:View SVG File.


Example 4

The element can arrange any subgroup with the number of elements. Each element can contain different formats and positions. Several lines of text (with the element):

Below is the SVG code:

Example

  Several lines:

    First line

    Second line

 

Try it »

Click to view:View SVG File.


Example 5

As linked text ( element):

Below is the SVG code:

Example

xmlns:xlink="http://www.w3.org/1999/xlink">

 

    I love SVG

 

Try it »

Click to view:View SVG File.