Chapter 6. Following Your Own Path
Chapter 6. Custom Shapes
A complete vector drawing format requires a way to draw arbitrary shapes and curves. The basic shape elements introduced in Chapter 5 may be useful building blocks, but they are no more flexible than CSS layout when it comes to crafting custom designs.
The <path> element is the drawing toolbox of SVG. Chances are, if you open up an SVG clip-art image or a diagram created with a graphics editor, you will find dozens or hundreds of kilobytes’ worth of <path> statements with only a smattering of <g> elements to provide positional organization. With <path> you can draw shapes that have straight or curved sections (or both), open-ended lines and curves, disconnected regions that act as a single shape, and even holes within the filled areas.
Understand paths, and you understand SVG.
The other custom shapes, <polygon> and <polyline>, are essentially shorthands for paths that only contain straight line segments.
This chapter introduces the instruction set for drawing custom shapes step by step, creating the outline by carefully plotting out each line segment and curve. For icons and images, it is relatively rare to write out the code this way, as opposed to drawing the shape in a graphics editor. With data visualization and other dynamically generated graphics, however, programmatically constructing a shape point by point is common, so learning the syntax is more important.
Even within graphic design, there will be times when ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access