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

Get SVG Text Layout now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.