Menu

1 / 5

Using CSS Masks to Improve Icons in Design Systems

DEV Community: css·Burton Smith·about 1 hour ago
#vtS0ogdZ
#devtocss#devto#dev#icons#instance
Reading 0:00
15s threshold

Design system icons often appear dozens of times on one screen, and inline SVG can create a separate subtree per instance. For our monochrome icons, CSS masks removed that markup, simplified updates, and made theming across Shadow DOM easier.

Here's how the approach works, where it scales, and when SVG may still be a better choice.

The problem with inline SVGs

Originally, every one of our icon components resolved to an SVG string. The component parsed the string, cloned an <svg> element, inserted it into its shadow root, and synchronized the node on updates.

That meant every icon on the page carried its own SVG subtree. On icon-heavy screens with lots of menus, tables, toolbars, trees, etc., the same small glyph was parsed, cloned, and stored over and over again.

It also created a fragile update path that produced real bugs, including an update loop and a viewBox regression.

The cost wasn't really about SVG being slow.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.