SVG tips & tricks


By now, SVG might seem straightforward, but trust me, it has its quirks that can make your data visualization journey challenging.

In this lesson, I'll share some tips and tricks that can save you hours of frustration β€” lessons I learned the hard way.

Members only
4 minutes read

SVG Elements Don't Have a Background Color

Unlike HTML elements, SVG elements do not support background colors directly. They also do not support borders.

If you want to create a background or add a border to your SVG, you need to draw a rectangle that covers the desired area. CSS properties like background-color or fill or border on the SVG element itself are not recognized and will be ignored.

Example:

Loading sandbox...

Text Alignment in SVG

Text alignment in SVG works differently compared to HTML. You can control both horizontal and vertical alignment using the text-anchor and alignment-baseline properties, which are unique to SVG.


Here's a summary of how they work:

text-anchor controls the horizontal alignment β†’
alignment-baseline controls the vertical alignment β†’
This is some text

Oh no! 😱

This lesson is not ready yet.

But we're working hard on it, releasing 1-2 lessons per week. If you're a student, check the discord channel for announcements! (discord logo logo above. )

πŸ™‡