CSS

css/icon-from-set

With a generated icon set, CSS uses its icon classes or mixin, never a url() hard-coded to an icon file.

minorstaticfe-css-architecture

Why

When the build turns a folder of source SVGs into a sprite or into icon classes, that output is the one place where an icon is sized, coloured, optimised and renamed. A url() written by hand to one SVG file skips all of it: the icon is not optimised, does not take currentColor, keeps working only until the file moves, and a second copy of the icon starts to drift. The rule runs only when the project has such a set: the helper icon-classes or icon-sprite in the profile, or icon classes or an icons module in the file.

Fix

Add the SVG to the icon source folder, rebuild, and use what the build generates: the class (.icon-search), the mixin (@include icons.icon(search)) or, in markup, the icon component or <use href="#icon-search"> (see html/project-icons and html/icon-from-set). Illustrations and photos are not icons and keep their url().

Examples

// bad
.search-btn::before { mask: url('../assets/icons/search.svg'); }
// good
.search-btn::before { @include icons.icon(search); }

Sources

Facts

Id
css/icon-from-set
Severity
minor
Check
static checked in the source by audit
Applies to
css scss less html vue svelte astro
Taught by the skill
fe-css-architecture CSS architecture and tokens
Since version
0.1.0

Rule file on GitHub

Read it in the terminal

npx github:dawidolko/frontend-skills explain css/icon-from-set