Skip to content

Features

Astro Iconset is a build-time SVG icon integration for Astro. Icons are resolved, optimized, and inlined at build time — there is no client-side icon runtime shipped to the browser.

Local SVG files

Drop .svg files in src/icons/ and reference them by name. Subfolders work too — src/icons/logos/astro.svg is logos/astro.

Iconify icon sets

Install any @iconify-json/* package and use set:icon-name in the name prop. Thousands of open-source sets available on Iconify.

Framework islands

Use Icon inside React, Vue, Svelte, Preact, or Solid components — import from astro-iconset/react, /vue, /svelte, /preact, or /solid.

SVG imports (?icon)

Import any .svg file as icon data with ?icon and pass it to icon={…}. Useful for one-off SVGs outside a shared icon directory.

Sprites

Repeated uses of the same icon share a <symbol> / <use> sprite pair automatically, keeping HTML smaller on icon-heavy pages.

SVGO optimization

Local SVG files are optimized with SVGO at build time. Fine-tune behavior with svgoOptions in the integration config.

Multiple icon directories

Map prefixes to directories with iconDirs. Reference brand:logo from src/brand-icons/logo.svg — mix as many named sets as you need.

SSR bundle control

For server or hybrid output, use include to ship only the specific Iconify icons your server routes actually use — not the entire set.


Place .svg files anywhere under your configured icon directory (src/icons/ by default). Files are picked up automatically — no manual registration.

---
import { Icon } from "astro-iconset/components";
---
<Icon name="logo" />
<Icon name="logos/astro" />

Configure a different directory, multiple directories, or named prefixes in the integration options.


Install any @iconify-json/* package and reference icons with the Iconify set:icon-name format.

Terminal window
npm install @iconify-json/mdi
<Icon name="mdi:account" size={24} title="Account" />

Browse available sets on Iconify Icon Sets or Icônes. Mix local icons and Iconify sets freely in the same project.


The Icon from astro-iconset/components is an Astro component — it only works in .astro files. For icons inside React, Vue, Svelte, Preact, or Solid components, import from the matching subpath:

FrameworkImport
Reactimport Icon from "astro-iconset/react"
Vueimport { Icon } from "astro-iconset/vue"
Svelteimport Icon from "astro-iconset/svelte"
Preactimport Icon from "astro-iconset/preact"
Solidimport Icon from "astro-iconset/solid"

See Framework islands for usage examples and notes on multi-JSX-framework projects.


Import a single .svg file as Iconify-compatible icon data using the ?icon query. Useful when the file lives outside a shared icon directory.

---
import { Icon } from "astro-iconset/components";
import mark from "../assets/mark.svg?icon";
---
<Icon icon={mark} title="Mark" />

The same icon prop works in framework adapters too. See SVG imports.


When the same icon is used more than once on a page, the first render emits a <symbol> in a hidden <svg>, and subsequent renders emit a <use> referencing it. This reduces HTML size on icon-heavy pages without any configuration.

Set is:inline on an Icon to bypass the sprite and render a full inline <svg> instead.


All local .svg files pass through SVGO at build time. The default configuration removes metadata, comments, and redundant attributes.

Override or extend SVGO behavior with svgoOptions:

astro.config.mjs
icon({
svgoOptions: {
multipass: true,
plugins: [{ name: "preset-default" }],
},
})

See the configuration reference for the full option shape.


Use iconDirs to map named prefixes to separate directories:

astro.config.mjs
icon({
iconDirs: {
brand: "src/brand-icons",
flags: "src/flag-icons",
},
})
<Icon name="brand:logo" />
<Icon name="flags:us" />

See Configuration for details on iconDir (string), iconDir (array), and iconDirs.


Every icon rendered with name receives a data-icon attribute matching the icon name. Use it as a CSS hook without adding extra classes:

[data-icon] {
width: 1em;
height: 1em;
}
[data-icon="mdi:account"] {
color: var(--color-brand);
}

See CSS & styling for more patterns.


When output is server or hybrid, all icons from every installed Iconify set may be pulled into the server bundle by default. Use include to restrict this:

astro.config.mjs
icon({
include: {
mdi: ["account", "account-plus", "home"],
},
})

See Deployment & SSR bundles and the include reference.


Both packages integrate SVG icons into Astro. The table below shows the key differences:

Featureastro-iconsetastro-icon
Local SVG files
Iconify sets (@iconify-json/*)
Build-time optimization (SVGO)
Sprites (<symbol> / <use>)
data-icon CSS attribute
?icon SVG import
Framework adapters (React / Vue / Svelte / Preact / Solid)
Named prefix directories (iconDirs)
SSR include filter