Skip to content

Icons

Resolve icon shortcut classes into CSS via Iconify integration.

The icons plugin resolves shortcut patterns like i-mdi:home into CSS declarations that display icons using mask-image or background-image. Icons are loaded from three sources in order: custom collections, locally installed @iconify-json/* packages, and an optional CDN fallback.

sh
pnpm add -D @pikacss/plugin-icons
sh
npm install -D @pikacss/plugin-icons
sh
yarn add -D @pikacss/plugin-icons
ts
import { defineEngineConfig } from '@pikacss/core'
import { icons } from '@pikacss/plugin-icons'

export default defineEngineConfig({
  plugins: [icons()],
  icons: {
    prefix: 'i-',
    mode: 'auto',
  },
})

Usage:

ts
// Use an icon
pika('i-mdi:home')

// Force mask mode (colorable with currentColor)
pika('i-mdi:home?mask')

// Force background mode
pika('i-mdi:home?bg')

Install icon collections as needed:

sh
pnpm add -D @iconify-json/mdi
sh
npm install -D @iconify-json/mdi
sh
yarn add -D @iconify-json/mdi

Config

PropertyDescription
prefixShortcut prefix(es) that trigger icon resolution, e.g. 'i-'.
modeCSS rendering technique: 'mask' (colorable via currentColor), 'bg' (background-image), or 'auto'.
scaleScaling factor applied to icon SVGs. Combined with unit for final dimensions.
collectionsCustom icon collections resolved before local or CDN sources.
customizationsIconify SVG customizations applied during icon loading.
autoInstallWhen true, auto-installs missing @iconify-json/* packages on first use.
cwdWorking directory for resolving locally installed icon packages.
cdnCDN URL template for fetching remote icon collections as a fallback.
unitCSS unit appended to icon dimensions, e.g. 'em'.
extraPropertiesAdditional CSS properties injected into every icon's style declaration.
processorPost-processing hook invoked after the icon CSS style item is built.
autocompleteExtra icon names to include in IDE autocomplete suggestions.

See API Reference — Plugin Icons for full type signatures and defaults.

Processor Metadata

processor receives the mutable generated style item and metadata describing the resolved icon:

ts
import { defineEngineConfig } from '@pikacss/core'
import { icons } from '@pikacss/plugin-icons'

export default defineEngineConfig({
  plugins: [icons()],
  icons: {
    processor(styleItem, meta) {
      // meta.collection: resolved Iconify collection
      // meta.name: resolved icon name
      // meta.svg: loaded SVG source
      // meta.source: 'custom' | 'local' | 'cdn'
      // meta.mode: final 'mask' or 'bg' mode after resolving 'auto'
    },
  },
})

The callback may mutate styleItem to inject or replace declarations before the shortcut result is returned.

Loading and Retry Behavior

Resolution checks custom collections first, then locally installed packages, then the configured CDN. A missing or temporarily unavailable icon logs a warning but is not cached as a permanent miss. Later resolutions retry the load, and failed CDN requests are removed from the collection cache before the next attempt.

Custom collection values are opaque Iconify loader functions or inline SVG maps. Their backing file paths are therefore not known to PikaCSS and cannot currently be registered as config dependencies. Editing files used by a custom collection does not automatically trigger a config reload; restart the dev process or touch the PikaCSS config after changing those files.

Next

  • Fonts — web font loading and management.
  • Reset — CSS reset stylesheets.