The Svelte package: one Icon component that renders any icon from fmicon. Works with Svelte 4 and 5 and SvelteKit.
What you can do:
- Render any icon with one component
- Set size, style, colour and stroke weight as props
- Import only the icon data you use
- Works with SvelteKit server rendering
Installation
Install the package with your package manager.
Basic Usage
Svelte uses one Icon component. Pass it any icon from fmicon.
<script>
import { Icon } from "fmicon-svelte";
import { home, notification, lock } from "fmicon";
</script>
<nav class="toolbar">
<Icon icon={home} size={24} />
<Icon icon={notification} size={24} variant="bold" />
<Icon icon={lock} size={24} color="#1265ec" />
</nav>
Customising Icons
Every icon takes the same options for size, style, colour and stroke weight.
// Size
<Icon icon={home} size={16} />
<Icon icon={home} size={32} />
// Style
<Icon icon={star} /> // linear (default)
<Icon icon={star} variant="bold" />
<Icon icon={star} variant="duotone" />
// Colour
<Icon icon={heart} color="#ff383c" />
// Stroke weight (line styles)
<Icon icon={home} strokeWidth={1} />
Full Example
A small toolbar with a few icons in different styles.
<script>
import { Icon } from "fmicon-svelte";
import { home, searchNormal, notification, heart, setting } from "fmicon";
</script>
<nav class="toolbar">
<Icon icon={home} size={20} />
<Icon icon={searchNormal} size={20} />
<Icon icon={notification} size={20} variant="bold" />
<Icon icon={heart} size={20} variant="bold" color="#ff383c" />
<Icon icon={setting} size={20} strokeWidth={1} />
</nav>
Props
Everything an icon accepts. Other SVG attributes are passed straight through.
| Prop | Type | Default | Description |
|---|---|---|---|
size | number | string | 24 | Width and height in pixels |
variant | "linear" | "outline" | "bold" | … | "linear" | Any of the 8 styles, plus "glass-light" |
color | string | currentColor | Any CSS colour; glass keeps its own |
strokeWidth | number | string | 1.5 | Line weight for linear, twotone, broken and duotone |
title | string | – | Accessible name; without it the icon is hidden from screen readers |
Styles
Every icon comes in 8 styles. Pick one with variant; the shape stays the same, so switching never shifts your layout.
"linear""outline""bold""bulk""twotone""broken""glass""duotone"<Icon icon={home} /> {/* linear */}
<Icon icon={home} variant="bold" />
<Icon icon={home} variant="glass" />
<Icon icon={home} variant="glass-light" /> {/* glass for light backgrounds */}
Tip: A common pattern: linear for idle tabs and bold for the selected one.
Styling and Colour
Icons draw with currentColor, so with no colour set they take the text colour of their parent. That makes hover states, dark mode and theme colours work without extra code.
- Inherit the parent's text colour (the default)
- Pass any hex, RGB, HSL or CSS variable as the colour
- Change the stroke weight on line styles: 1 thin, 1.5 default, 2 bold
- Add classes with
class, including Tailwind utilities
<Icon icon={home} color="#1265ec" />
<Icon icon={home} color="var(--brand)" />
<Icon icon={home} class="text-blue-500 hover:text-blue-600" />
Tip: Glass icons keep their own colours, so color doesn't change them. Use glass-light on light backgrounds.
Accessibility
Icons are hidden from screen readers (aria-hidden) unless you give them a name with title or aria-label.
<button aria-label="Delete item">
<Icon icon={trash} size={20} />
</button>
<Icon icon={warning2} size={20} color="#ff383c" title="Warning" />
Tip: Next to visible text, leave the icon unnamed: the text already says it, and screen readers won't read it twice.
Performance
Packages are marked "sideEffects": false and every icon is its own module, so your bundle only gets the icons you import.
// Good: only these icons end up in the bundle
import { Icon } from "fmicon-svelte";
import { home, lock } from "fmicon";
// Avoid: pulls in all 891 icons
import * as Icons from "fmicon";
| Method | Bundle impact | Best for |
|---|---|---|
fmicon-react, /vue, /react-native | Only the icons you import | Apps with a bundler |
…/icons/<slug> | Exactly one icon per import | Setups without tree-shaking |
fmicon + toSvg | Only the icons you import | Vanilla JS, web components |
CDN <img> | Nothing in the bundle | Static sites, prototypes, email |
TypeScript
Types ship with every package. Icon names autocomplete, and so do the styles.
import type { IconData, IconVariant } from "fmicon";
const variant: IconVariant = "duotone";
function render(icon: IconData) {
return toSvg(icon, { variant });
}
Troubleshooting
Common problems and how to fix them. Not listed? Open an issue on GitHub.
// Data exports are camelCase; reserved words get "Icon"
import { arrowCircleRight, exportIcon } from "fmicon";
// Glass keeps its own colours; pick another style
<Icon icon={home} variant="bold" color="#1265ec" />
// strokeWidth only applies to linear, twotone, broken and duotone
<Icon icon={home} variant="linear" strokeWidth={2} />