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:
-
xandyThe attribute defines the coordinates of the top-left corner of the text, i.e., the starting position of the text. -
font-familyThe attribute defines the font name of the text, which can be a system font or a custom font. -
font-sizeThe attribute defines the font size of the text, in pixels. -
fillThe attribute defines the color of the text. -
text-anchorThe attribute defines the text anchor, i.e., the alignment of the text relative to the specified coordinates; common values are "start" (default, left-aligned), "middle" (center-aligned), and "end" (right-aligned).
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).
Example 1
Write a text:
Below is the SVG code:
Example
Try it »
Click to view:View SVG File.
Example 2
Rotated text:
Below is the SVG code:
Example
Try it »
Click to view:View SVG File.
Example 3
Text on a path:
Below is the SVG code: