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 11000 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>

  • xx coordinate of the starting point of the baseline
  • yy coordinate of the starting point of the baseline
  • dxfrom the starting point of the baseline, shifts the text in the x-axis
  • dyfrom the starting point of the baseline, shifts the text in the y-axis
  • rotaterotate each individual glyph (separate with comma to specify different rotation for each glyph)
  • textLengthwidth of the "text box" (controls letter spacing)
  • lengthAdjustcontrols how the text should fill the width of the "text box"; specify spacing or spacingAndGlyphs
| LIVE PREVIEW
Hello, Everyone!

<tspan>

Defines a subtext within a <text> element or another <tspan> element.

  • xx coordinate of the starting point of the baseline (normally continues where the preceding text ended; setting this value affects the following text)
  • yy coordinate of the starting point of the baseline (normally continues where the preceding text ended; setting this value affects the following text)
  • dxfrom the starting point of the baseline, shifts the text in the x-axis (setting this value affects the following text)
  • dyfrom the starting point of the baseline, shifts the text in the y-axis (setting this value affects the following text)
  • rotaterotate each individual glyph (separate with comma to specify different rotation for each glyph)
  • textLengthwidth of the "text box" (controls letter spacing)
  • lengthAdjustcontrols how the text should fill the width of the "text box"; specify spacing or spacingAndGlyphs
| LIVE PREVIEW
You are NOT a banana!

<textPath>

Renders the text along the given path.

  • paththe path data, e.g. M 10,30 A 20,20 0,0,1 50,30 ...
  • hrefURL to the path or basic shape to render the text, e.g. #my-path; if the path attribute is specified, this attribute is ignored.
  • sidewhich side of the path to render the text, relative to the path direction; specify left (default) or right (reverses the path direction)
  • startOffsetoffsets the text from the start of the path
  • textLengthwidth of the "text box" (controls letter spacing)
  • lengthAdjustcontrols how the text should fill the width of the "text box"; specify spacing or spacingAndGlyphs
| LIVE PREVIEW
Quick brown fox jumps over the lazy dog.

References