Skip to content

Local & Iconify icons

Place .svg files under src/icons/ by default (or set iconDir / iconDirs). The name prop is the file path relative to that directory, without the .svg extension.

  • Directorysrc/
    • Directoryicons/
      • logo.svg
      • close.svg
      • Directorylogos/
        • astro.svg
        • github.svg

The name prop maps directly to the relative path without .svg:

Filename value
src/icons/logo.svg"logo"
src/icons/close.svg"close"
src/icons/logos/astro.svg"logos/astro"
src/icons/logos/github.svg"logos/github"
---
import { Icon } from "astro-iconset/components";
---
<Icon name="logo" />
<Icon name="logos/astro" />
  • Use any characters that are valid in a file path: letters, numbers, hyphens (-), underscores (_), and forward slashes for subfolders.
  • The name is case-sensitive on case-sensitive file systems (Linux, most CI). Logo and logo are different icons.
  • The .svg extension is never part of the name.
  • Spaces in file names work but are awkward in name — prefer hyphens.

Pass an array to iconDir to merge several folders into one flat namespace. Icons from every folder use the same naming rules — the path is relative to each root, and keys must be unique across the merged set.

  • Directorysrc/
    • Directoryicons/
      • logo.svg
      • close.svg
    • Directoryextra-icons/
      • star.svg
      • badge.svg
Filename (merged local set)
src/icons/logo.svg"logo"
src/icons/close.svg"close"
src/extra-icons/star.svg"star"
src/extra-icons/badge.svg"badge"
astro.config.mjs
icon({
iconDir: ["src/icons", "src/extra-icons"],
});

Duplicate keys fail the build — for example both src/icons/logo.svg and src/extra-icons/logo.svg resolve to name="logo". Rename one file or switch to iconDirs with prefixes.

Map a prefix to each directory. Files are referenced as prefix:name (still without .svg). Different prefixes can reuse the same file name — brand:logo and ui:logo are not a collision.

  • Directorysrc/
    • Directorybrand-icons/
      • logo.svg
      • wordmark.svg
    • Directoryui-icons/
      • logo.svg
      • menu.svg
      • close.svg

Same file name in two folders is fine — the prefix keeps them distinct (brand:logo vs ui:logo).

Filename
src/brand-icons/logo.svg"brand:logo"
src/brand-icons/wordmark.svg"brand:wordmark"
src/ui-icons/logo.svg"ui:logo"
src/ui-icons/menu.svg"ui:menu"
src/ui-icons/close.svg"ui:close"
astro.config.mjs
icon({
iconDirs: {
brand: "src/brand-icons",
ui: "src/ui-icons",
},
});
<Icon name="brand:logo" />
<Icon name="ui:logo" />
<Icon name="ui:menu" />

Files are optimized with SVGO at build time. See svgoOptions to customize the behaviour.


Iconify bundles many open-source sets as @iconify-json/* npm packages. After you install a package, icons are available to the Icon component by set:icon-name.

Browse sets on Iconify Icon Sets or Icônes. The identifier shown on those sites is the set:icon-name value to use in name.

Example: Material Design Icons (mdi).

Terminal window
npm install @iconify-json/mdi
---
import { Icon } from "astro-iconset/components";
---
<Icon name="mdi:account" />
<Icon name="mdi:home" size={24} />

You can mix local icons and multiple Iconify sets in the same project.