css


目录

title: Generating CSS for icons
functions:
  getIconsCSS: '/docs/libraries/utils/get-icons-css.md'

CSS for icons

Iconify API can dynamically generate CSS for icons, where icons are used as background or mask image.

This allows rendering icons with a simple [tag]span tag without any components.

Query

API URI that generates CSS is [url]/{prefix}.css?icons={icons}, where:

Examples:

hint: /openmoji.css?icons=axe,balance-scale
src: api/openmoji.css
hint: /mdi.css?icons=account-box,account-cash,account,home
src: api/mdi.css

Using icons in HTML is easy: use a placeholder element with 2 class names: class name for an icon set and class name for icon:

<span class="icon--openmoji icon--openmoji--axe"></span>
<span class="icon--mdi icon--mdi--account"></span>

Why 2 classes? This allows splitting common style in separate rule, reducing duplication and making it easier to target all icons from an icon set.

If you want to reference icons with 1 simple class, you can use [prop]selector and [prop]common options. See examples below.

Options

Optional parameters:

Other optional parameters are the same as in [func]getIconsCSS() function of Iconify Utils.

Color and mode

There are two types of icons:

You can use both types in CSS.

Icons with hardcoded palette are rendered as background images:

include common/icon-types-palette

Monotone icons are rendered as mask images with background color set to [prop]currentColor:

include common/icon-types-monotone

Using [prop]currentColor as background color makes it easy to change icon color by changing text color:

<span class="icon--bi icon--bi--bell-fill" style="color: green"></span>

You can force background or mask mode by adding [prop]mode parameter: [url]&mode=background or [url]&mode=mask

You can also use [prop]color parameter to convert monotone icons to icons with palette: [url]&color=green.

CSS variables

include: libraries/utils/css-color
<span class="icon--mdi icon--mdi--home" style="color: var(--icon-color)"></span>

More examples

You can customise generated stylesheet using various optional parameters.

Getting CSS for one icon with custom selector by adding [prop]selector parameter:

hint: /openmoji.css?icons=axe&selector=.axe-icon
src: api/openmoji-axe.css

CSS for one icon with a pseudo selector, using [prop]selector and [prop]selector parameters:

hint: /material-symbols.css?icons=check-box-outline-rounded&selector=.checkbox-checked::after&pseudo=1
src: api/checkbox.css

Same as above, but sets icon color to green:

hint: /material-symbols.css?icons=check-box-outline-rounded&selector=.checkbox-checked::after&pseudo=1&color=green
src: api/checkbox-color.css

CSS for multiple icons with pseudo selectors requires multiple parameters. It requires using at least [prop]icon and [prop]pseudo parameters, optionally with [prop]common and [prop]override parameters:

hint: /line-md.css?icons=account-add,account-delete&selector=.icon--{prefix}--{name}::after&pseudo=1
src: api/line-md.css
hint: /line-md.css?icons=account-add,account-delete&selector=.icon--{prefix}--{name}::after&common=.icon--{prefix}::after&override=.icon--{prefix}.icon--{prefix}--{name}::after&pseudo=1
src: api/line-md2.css

Want to support old browsers? Add [url]&var=null:

hint: /openmoji.css?icons=axe,balance-scale&var=null
src: api/openmoji-novar.css

... which might result in duplicate content for monotone icons:

hint: /line-md.css?icons=account-add,account-delete&var=null
src: api/line-md-novar.css

See [func]getIconsCSS() function of Iconify Utils for more examples.


版本号 #2
由 壳壳虫 创建于 2026-10-31 14:15:30 UTC
由 壳壳虫 更新于 2026-10-31 14:15:31 UTC