Text
This page explains how to insert texts in SVG.
SVG font attributes
font-family
A prioritized list of what font family to use, e.g. Arial, Helvetica, sans-serif.
font-size
Constrols size of text (from baseline to baseline), e.g. 10 or 2em.
font-style
Specify normal, italic, or oblique.
font-weight
Sets the font weight (boldness). Specify normal, bold, lighter (one relative weight lighter), bolder (one relative weight bolder), or a number between 1–1000 like 400 or 700.
font-variant
Indicates which glyph variants to use (separated by space), e.g. small-caps or common-ligatures small-caps. See CSS font-variant for the complete list.
SVG text attributes
text-decoration
Adds decoration to text. Shorthand for text-decoration-line and text-decoration-style
Specify something like none, underline, underline double.
text-anchor
How to align the text given the starting baseline point.
Specify start, middle, or end.
SVG elements
<text>
x— x coordinate of the starting point of the baseliney— y coordinate of the starting point of the baselinedx— from the starting point of the baseline, shifts the text in the x-axisdy— from the starting point of the baseline, shifts the text in the y-axisrotate— rotate each individual glyph (separate with comma to specify different rotation for each glyph)textLength— width of the "text box" (controls letter spacing)lengthAdjust— controls how the text should fill the width of the "text box"; specifyspacingorspacingAndGlyphs
<tspan>
Defines a subtext within a <text> element or another <tspan> element.
x— x coordinate of the starting point of the baseline (normally continues where the preceding text ended; setting this value affects the following text)y— y coordinate of the starting point of the baseline (normally continues where the preceding text ended; setting this value affects the following text)dx— from the starting point of the baseline, shifts the text in the x-axis (setting this value affects the following text)dy— from the starting point of the baseline, shifts the text in the y-axis (setting this value affects the following text)rotate— rotate each individual glyph (separate with comma to specify different rotation for each glyph)textLength— width of the "text box" (controls letter spacing)lengthAdjust— controls how the text should fill the width of the "text box"; specifyspacingorspacingAndGlyphs
<textPath>
Renders the text along the given path.
path— the path data, e.g.M 10,30 A 20,20 0,0,1 50,30 ...href— URL to the path or basic shape to render the text, e.g.#my-path; if thepathattribute is specified, this attribute is ignored.side— which side of the path to render the text, relative to the path direction; specifyleft(default) orright(reverses the path direction)startOffset— offsets the text from the start of the pathtextLength— width of the "text box" (controls letter spacing)lengthAdjust— controls how the text should fill the width of the "text box"; specifyspacingorspacingAndGlyphs
References
- <text> (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Element/text
- <tspan> (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Element/tspan
- <textPath> (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Element/textPath
- lengthAdjust (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/lengthAdjust
- font-family (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/font-family
- font-size (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/font-size
- font-style (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/font-style
- font-weight (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/font-weight
- font-variant (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/font-variant
- text-decoration (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/text-decoration
- text-anchor (MDN) — https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/text-anchor