https://me.micahrl.com/blog/svg-triangle-of-compromise/ [stamp-tint] [stamp-blac] * fontawesome/solid/at contact * fontawesome/solid/paragraph blog * fontawesome/solid/volume-down whispers SVG triangle of compromise Technologies: * fontawesome/solid/code svg Tags: * fontawesome/solid/tag iframes Incomplete, update pending This is a short update on 2024-07-29 after some discussion on Hacker News and Mastodon. It turns out that I was wrong about the original thrust of my post . I will make an update, but it's not ready yet (I told my boss that I need to poast but he still wanted me to work today). The short version: SVGs with tags offer a no compromise solution. Scott Jehl made a great interactive demo of this. Thanks to everyone on HN and to Scott for the feedback! Feed warning If you're reading this via the web feed (RSS), I recommend viewing it on the web instead, as I'm using elements as well as some feed-reader-unfriendly CSS and JavaScript in this post. Updates * 2024-07-29: Add a note about pending updates and a link to Scott Jehl's demo * 2024-07-25: Add list of properties to each subheading, show tags With SVGs on the web, you get to choose any two: * Stylable: can be colored with CSS (including foreground, background, :hover states, etc) * Cacheable: load once, use on other pages is free * Dimensional: has an intrinsic width and height stylable cacheable dimensional tag tag nothing Referencing SVGs from an element * stylable * cacheable * dimensional An SVG referenced via an tag works like any other image. If you load the same image on multiple pages, it will be cached and not re-downloaded. It can be used without specifying width and height to be displayed at its natural size, or with only one of the two specified for it to be displayed proportionally, or can be made to automatically fit its container. Other image types like PNG or JPEG files only support being referenced this way in the first place. Displaying an SVG via an tag * stylable * cacheable * dimensional An SVG defined via an can have its objects styled with CSS. The CSS properties that apply to SVGs are sometimes different than those that apply to HTML elements, like fill instead of color, but it's all CSS in the end, and you can use the same stylesheet to style SVG elements along with the rest of your page. An SVG defined this way has another advantage: it can use the currentColor value for its fill and stroke properties, which means that it will automatically inherit the text color of its parent element. The shapes support :hover states and other CSS pseudo-classes, too. In fact, they can have styling dynamically applied via JavaScript just like any other element! It's implemented in the diagram above, try hovering over any of the text labels. Of course, placing the SVG inline to the HTML means it cannot be cached, any more than a

or a

is cached when it's repeated on multiple pages. This is almost never a problem with text, which tends to be very small and not be repeated on multiple pages, but might waste bandwidth if used for SVGs used often, like a logo or icon. Displaying an