Web Icons: CSS Token Engine, image-set Pseudo-Elements, and Component APIs
How to choose icon techniques, build a CSS mask engine, serve multi-resolution assets, and use component icon props.
This page brings together Using and managing icons from Chrome’s modern web guidance (CSS-driven icons, SVG patterns, and browser workarounds), Resolution Optimized Pseudo Elements (responsive bitmap icons in CSS), and Cloudflare’s Icons, Cards, and RSSButton documentation for named Iconify icons in UI components.
Choosing an icon technique: CSS, SVG, or components
Section titled “Choosing an icon technique: CSS, SVG, or components”Icon storage and rendering are separate choices. People usually arrive here because icons look wrong (alignment, color, blur on retina), multiply HTTP requests, or do not update with hover or theme—and they want a rule for CSS vs inline SVG vs a component icon prop.
Icon storage and rendering are separate choices. For example, an SVG sprite can supply an icon to the CSS icon system or be referenced with
<use>.— Chrome, Using and managing icons
| Approach | Use when | Trade-off |
|---|---|---|
| CSS icon system (masks, custom properties) | CSS should pick, swap, or theme icons (states, component defaults) | More setup; masked icons are effectively single-color unless you use backgrounds |
SVG with <use> |
You reuse a symbol and inherited color or custom properties on the symbol are enough | Page CSS cannot select inside the cloned tree; external sprites are same-origin only |
| Inline SVG | You need to style or animate paths directly | More HTML per instance unless you pair with local <use> |
<img> + CSS filters |
— | Chrome’s guidance says to avoid this for recoloring: filters do not map reliably to arbitrary CSS colors |
| Framework icon components | Docs or app shells already expose icon="ph:…" or SVG strings |
Depends on the design system (Iconify names, bundled SVGs, etc.) |
To decide, ask two questions. Does CSS need to pick or swap the icon (component defaults, state changes, theming)? If yes, use the CSS icon system. Do you need to reach inside the icon beyond color? If yes and you control the icon source, design the symbol with custom properties and use
<use>; if you do not control the source, inline the SVG. Third-party icon sets rarely expose custom properties, so<use>against them gives you color and little else.— Chrome, Using and managing icons
Embedded, remote, and sprite icons: what to load when
Section titled “Embedded, remote, and sprite icons: what to load when”Both the CSS icon system and <use> can use a data URI, a file, or a sprite.
Embedding (data URIs or inline SVG) avoids a request and renders with the first paint, but bloats CSS or HTML and cannot be cached separately, so it suits a small set of icons that appear on every page. Individual files are cached independently and loaded on demand, at the cost of one request each. A sprite is one cacheable request for the whole set, but downloads every icon whether used or not, and
<use>can only reference a sprite from the same origin. Prefer embedding for a handful of core icons and a sprite or individual files for larger sets.— Chrome, Using and managing icons
If a page renders very large numbers of icons, Chrome notes that benchmarks depend on browser and implementation; treat stress-test anecdotes as a reason to measure your own page, not as a universal rule.
CSS icon engine: custom properties, masks, and pseudo-elements
Section titled “CSS icon engine: custom properties, masks, and pseudo-elements”The primary pattern in Chrome’s guide treats icons as design tokens: each icon is a custom property holding an image, and elements display one by setting --icon-start or --icon-end.
Icons are design tokens: each icon is a custom property holding an image, and any element can display one by setting –icon-start or –icon-end. The engine combines three CSS capabilities:
Registered custom properties (@property) keep –icon-start and –icon-end from inheriting, so an icon set on a component does not cascade into its children. Container style queries (@container style(…)) detect when an element has an icon assigned and render it, with no class or markup changes. CSS masks and currentColor render the icon in a pseudo-element that follows the element’s text color.
— Chrome, Using and managing icons
How to define --icon-* tokens without broken relative URLs
Section titled “How to define --icon-* tokens without broken relative URLs”Define tokens with inline SVG data URIs or root-relative URLs (for example url("/icons/trash.svg")). A pitfall: a relative URL on a custom property may resolve against the stylesheet where the property is used, not where it is defined.
When relative URLs are unavoidable, such as stylesheets in different directories, register the token with a syntax that starts with <url> and declare the actual URL on :root. This resolves against the declaring stylesheet in every browser
— Chrome, Using and managing icons
Chrome also warns not to rely on registering a token with the <image> syntax and the URL only in initial-value: Chrome and Safari resolve those URLs against the document (Firefox differs). Root-relative URLs and data URIs stay simpler when they are an option.
How --icon-start and --icon-end render on ::before and ::after
Section titled “How --icon-start and --icon-end render on ::before and ::after”Two pieces of CSS connect assignment to pixels:
- Register
--icon-startand--icon-endwith@property,syntax: "*", andinherits: falseso a button’s icon does not appear on every descendant. - A
@container style(--icon-start)block paints a masked pseudo-element, forwards the token withinheritinside the query, and usescurrentColorfor fill by default.
Spacing, size, and vertical offset use --icon-style-* properties so a toolbar can restyle every icon inside it. Chrome documents why vertical-align uses cap height, why flex: none stops icons from shrinking in flex layouts, pointer-events: none, forced-color-adjust: none for forced-colors mode, and content: "" / var(--icon-style-alt, "") for accessible names on generated content.
For trailing icons, mirror the pattern with --icon-end and ::after, mask: var(--icon-end), and margin-inline-start for spacing.
Icon-only controls and state changes without extra markup
Section titled “Icon-only controls and state changes without extra markup”Standalone icons use the .icon class on an empty element and set --icon; a rule maps --icon to --icon-start for leading placement. Icon-only buttons need aria-label or --icon-style-alt; otherwise the generated icon is decorative.
Because the icon is only a property, toggling state is a normal cascade override—for example --icon-start on [aria-expanded="true"] instead of swapping DOM nodes.
The main benefit of icons as custom properties is that they participate in the cascade. Set an icon on a selector and every matching element gets it, with no markup changes
— Chrome, Using and managing icons
SVG <use> when the CSS engine is not enough
Section titled “SVG <use> when the CSS engine is not enough”When you need structure inside the glyph, combine one inline SVG definition with <use href="#id"> for repeats on the same page; reserve cross-page external sprites for shared sets and remember same-origin limits.
Mark decorative SVGs with aria-hidden="true" and put the accessible name on the control, as with the CSS system.
image-set in pseudo-elements: resolution and format for bitmap icons
Section titled “image-set in pseudo-elements: resolution and format for bitmap icons”When icons are raster files (not mask tokens), Chrome’s performance guide shows image-set() on a pseudo-element’s content or background-image (with content: "" for backgrounds).
You can use the image-set() function directly within the content property of a pseudo-element, or within its background-image property (while setting content: “”). Note that while providing both the image format via type() and the resolution (like 1x or 2x) yields the best results, both of these arguments are optional.
— Chrome, Resolution Optimized Pseudo Elements
Order formats from most optimized to least (for example AVIF, then WebP, then PNG); the browser stops at the first supported type:
.icon-button::before { content: image-set( url("icon.avif") type("image/avif") 1x, url("icon-2x.avif") type("image/avif") 2x, url("icon.webp") type("image/webp") 1x, url("icon-2x.webp") type("image/webp") 2x, url("icon.png") type("image/png") 1x, url("icon-2x.png") type("image/png") 2x ); display: inline-block; margin-right: 8px; vertical-align: middle;}Use this path when you need multi-resolution bitmaps in generated content; use the token + mask engine when color should follow text and icons swap purely in CSS.
Component icon APIs: Iconify names, Nimbus, and SVG strings
Section titled “Component icon APIs: Iconify names, Nimbus, and SVG strings”Documentation and product UIs often expose icons through components instead of raw CSS tokens.
Cloudflare docs site: Icon, Card, and LinkCard
Section titled “Cloudflare docs site: Icon, Card, and LinkCard”Cloudflare’s style guide describes two icon component sources: a standalone Nimbus Icon for product SVGs under /src/icons/*.svg, and Iconify string names on Card and LinkCard.
There are two icon components which pull from two different icon sets.
— Cloudflare, Icons
Components like Card and LinkCard accept a plain icon string prop — any iconify ↗︎ icon name.
— Cloudflare, Icons
Example from Cards:
import { Card } from "~/components";
<Card title="Check this out" icon="ph:puzzle-piece"> Interesting content you want to highlight.</Card>Older legacy icon names may still map at build time; new content should use Iconify names directly. Cards notes you can pick icons from the documented icon list for cards—same pattern as in the Icons page.
The RSSButton icon prop defaults to "rss" (mapped to ph:rss-simple) and accepts any Iconify name, rendered through Nimbus Icon.
When components take an SVG string (RealtimeKit pattern)
Section titled “When components take an SVG string (RealtimeKit pattern)”In app UI kits, a common alternative is an icon component that accepts raw SVG markup—for example Cloudflare RealtimeKit’s rtk-icon (“accepts an svg string and renders it”) and React Native RtkIcon with a required icon string property. That fits icons bundled in code or returned from config, not a global Iconify catalog. Loading and spinners (rtk-spinner, RtkLoaderView) are separate from glyph choice but often sit beside icons in the same UI shell.
Pick CSS tokens for site-wide theming and state; Iconify component props for doc/product shells; SVG-string components when the icon payload is dynamic or app-specific.
Common mistakes
Section titled “Common mistakes”- Using
<img>plus CSS filters to recolor icons instead of masks, inline SVG, orcurrentColor(see Chrome’s technique table above). - Letting
--icon-startinherit so every child renders the same pseudo-element icon—fix with@property { inherits: false }or Safari’s documented reset pattern. - Relative icon URLs in tokens that resolve against the wrong stylesheet; prefer root-relative or data URIs, or the <url>-first
@propertypattern on:root. - External SVG sprites referenced with
<use>from another origin (fails silently). - Icon-only buttons without
aria-labelor--icon-style-alt, so assistive tech gets no name. - Bitmap pseudo-element icons without
image-set()ordering from AVIF/WebP down to PNG/JPEG.
How to check this on your site
Section titled “How to check this on your site”- In DevTools, inspect an element that should show a CSS token icon: confirm
--icon-startor--icon-endis set, the@container style(...)rules apply, and the pseudo-element has a non-emptymask(orimage-setcontentfor bitmaps). - Toggle forced-colors mode and hover/focus states; icons should remain visible (
forced-color-adjust) and swap correctly on state selectors. - On a retina display or DPR 2 emulation, verify
image-set()picks2xassets per Resolution Optimized Pseudo Elements. - For component pages using Cloudflare patterns, confirm Iconify names render on Cards and the standalone Icon component loads the expected glyph.
- You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact sentence you are asking about so it can be corrected.