Skip to content

Components

Astro Iconset’s main API is Icon, which renders optimized SVG markup in your HTML.

Import from astro-iconset/components and use it like any Astro component:

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

Rendering happens on the server; there is no client-side icon runtime.

You can pass name or icon, plus standard SVG attributes (including ARIA).

PropTypeDescription
namestringLocal slug (for example logo or logos/astro) or Iconify id (mdi:account)
iconAstroIconImportData from import x from "*.svg?icon" — mutually exclusive with name
titlestringAdds a <title> for accessibility
descstringAdds a <desc> when needed
sizenumber | stringShorthand for width and height
width / heightnumber | stringExplicit dimensions
is:inlinebooleanWhen true, inlines the SVG without the sprite <symbol> path
interface Props extends HTMLAttributes<"svg"> {
name?: string;
icon?: AstroIconImport;
"is:inline"?: boolean;
title?: string;
desc?: string;
size?: number | string;
width?: number | string;
height?: number | string;
}

Use name or icon, not both. If both are passed, icon takes priority and a dev-mode warning is logged.

When size and width/height are both provided, the explicit width/height values win and size is used only as a fallback for the axis that has no explicit value. A dev-mode warning is also logged.

By default, the first use of an icon on a page can emit a <symbol> and later uses reference it with <use>, which keeps HTML smaller when the same icon repeats.

Sprite output (default — two uses of "logo" on one page):

<!-- Emitted once, usually near the top of the page -->
<svg aria-hidden="true" style="display:none">
<symbol id="ai:local:logo" viewBox="0 0 24 24">
<path d="" />
</symbol>
</svg>
<!-- Every <Icon name="logo" /> after the first -->
<svg data-icon="logo">
<use href="#ai:local:logo" />
</svg>

Inline output (is:inline — always a full copy of the SVG):

<svg data-icon="logo" viewBox="0 0 24 24">
<path d="" />
</svg>

Set is:inline when:

  • the icon only appears once on a page and you want a simpler DOM
  • you need to directly style inner SVG elements (paths, circles) with scoped CSS without :global(…)
  • you are generating static HTML where the <symbol> reference would be split across chunks
---
import { Icon } from "astro-iconset/components";
---
<Icon name="mdi:account" size={32} title="Account" />
---
import { Icon } from "astro-iconset/components";
import mark from "../assets/mark.svg?icon";
---
<Icon icon={mark} title="Mark" />

You cannot import Astro’s Icon directly inside React/Vue/Svelte files. Either:

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