O'Reilly logo

SVG Text Layout by Kurt Cagle, Amelia Bellamy-Royds

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 3. Colorful Language

The shape and size of SVG letters may be controlled by the standard CSS font selection properties, but the final appearance is uniquely SVG. As far as painting the text, letters are just another vector shape in SVG, defined by the Bézier curves within the vector font files. Results may be strange if you use a bitmap font, but those are few and far between on modern computers.

Like all SVG shapes, the paint of text is affected by two properties: fill for the interior, and stroke for the outline.

Fill and Stroke

The normal shape of a letter in an OpenType-compatible vector font is created by filling in the outlines from the font file. Therefore, for “normal” looking text in SVG, you set the fill property to a solid color. For more adventurous text, you can use gradient or patterned fills, or no fill at all, just a stroked outline.

Each glyph is painted individually, in logical reading order. If the text has a thick stroke, the overlap of each letter on previous ones may be visible. For cursive scripts, strokes are often unattractive because they highlight the edges of each glyph, counteracting the impression of a continuous stroke from one letter to the next.

Tip

As with every other shape in SVG, the default appearance for text is solid black fill and no stroke.

Both fill and stroke have the same allowed values:

  • The keyword none

  • A color value, using any CSS color format supported by the software—keywords, hex colors like #080844 or #fab, or functions ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required