How to Make a Gingerbread Figure with SVG
Moving styling properties to CSS
Since our SVG is living inside an HTML file now, we can assign CSS classes to each element and move some of the attributes to CSS. We can only move the presentation attributes though. Position attributes and attributes that define the shapes have to stay in HTML. But colors, stroke, and font attributes can be moved to CSS.
Rounded lines
We already saw the fill
and some of the stroke
properties, but here’s another styling property. The stroke-linecap
. This can make our line cap rounded. Note that the legs and the arms are simple lines here.
To give you a comparison if we remove the line cap and set a smaller stroke-width, then this is how it would look like.
But by setting a thick stroke width and a round line cap we can shape legs and arms for our figure.
Rounded rectangles
Now, let’s add the mouth of the figure. We use another rectangle for it. Note the rx
property at its definition. This will make the edges of the rectangle rounded. It is similar to the border-radius
property for regular HTML elements.
Gingerbread figure
Once we put it all together, and add eyes and buttons, this is how the final code looks like: