Iconify icons for Svelte
Access all Iconify icons in your SvelteKit project. Uses static code analysis to detect icon usage and bundles only the icons you need, enabling offline access and minimal bundle sizes.
npm install sv-iconify -D
# or
pnpm add sv-iconify -D
Add the Vite plugin to your vite.config.ts:
import { defineConfig } from "vite";
import { sveltekit } from "@sveltejs/kit/vite";
import { svIconify } from "sv-iconify/vite";
export default defineConfig({
plugins: [
svIconify(), // Required - scans your code and bundles icons
sveltekit(),
],
});
The plugin is required for icons to work. It scans your code for icon usage and creates a bundle containing only the icons you use.
see below section for configuration options.
Import and use the Icon component in your Svelte files:
<script>
import { Icon } from "sv-iconify";
</script>
<Icon icon="mdi:home" />
<Icon icon="carbon:user-avatar" width={32} />
<Icon icon="lucide:settings" color="blue" />
| Property | Type | Description | Default |
|---|---|---|---|
icon |
string | Icon name in format iconset:name (e.g., "mdi:home", "carbon:user") |
— (required) |
width |
number | string | Icon width | 16 |
height |
number | string | Icon height | 16 |
color |
string | Icon color | "inherit" |
strokeWidth |
number | Stroke width for stroke-based icons | — |
rotate |
string | number | Rotation angle (e.g., "90deg", 90) |
0 |
hFlip |
boolean | Flip horizontally | false |
vFlip |
boolean | Flip vertically | false |
style |
string | Additional CSS styles | — |
<!-- Basic usage -->
<Icon icon="mdi:home" />
<!-- Custom size -->
<Icon icon="carbon:user" width="{24}" />
<Icon icon="carbon:user" width="1rem" />
<Icon icon="carbon:user" width="24" />
<!-- Custom color -->
<Icon icon="lucide:heart" color="red" />
<Icon icon="lucide:heart" color="var(--red-600)" />
<!-- Rotation -->
<Icon icon="mdi:arrow-right" rotate="90deg" />
<!-- Flip -->
<Icon icon="mdi:arrow-left" hFlip />
<Icon icon="mdi:arrow-left" vFlip />
The plugin uses static code analysis to scan your source code for icon usage (e.g., icon="mdi:home") and creates an optimized bundle:
If an icon can't be found in the bundle, it falls back to the Iconify API and fetches the icon over the network.
The Vite plugin can be configured with the following options:
sourceDir (string)
node_modules - node_modules/sv-iconify/dist/data/jsonoutputPath (string)
'static/_sv-iconify/icons-bundle.json'.scanDir (string)
'src'.includes (object)
includes.iconSets (string[])['lucide', 'tabler']).includes.icons (string[])['lucide:home', 'tabler:package']).fallback (boolean)
true.import { defineConfig } from "vite";
import { sveltekit } from "@sveltejs/kit/vite";
import { svIconify } from "sv-iconify/vite";
export default defineConfig({
plugins: [
svIconify({
sourceDir: "./custom-icons",
outputPath: "static/icons/icons-bundle.json",
scanDir: "src",
includes: {
iconSets: ["mdi", "carbon"],
icons: ["lucide:home", "tabler:package"],
},
}),
sveltekit(),
],
});
MIT