Vanilla JS / CDN

The framework-free package. Every icon is plain data with a toSvg helper, so it works in any bundler, in Node, or straight from a CDN.

What you can do:

  • Render any icon to an SVG string
  • Pick size, style, colour and stroke weight
  • Import only the icons you use
  • Load files straight from cdn.fmicon.dev, no install

Installation

Install the package with your package manager.

Basic Usage

Every icon is exported as data. toSvg turns it into an SVG string you can put anywhere in the page.

main.js
import { home, notification, lock, toSvg } from "fmicon";

document.querySelector("#home").innerHTML = toSvg(home, { size: 24 });
document.querySelector("#alerts").innerHTML = toSvg(notification, { size: 24, variant: "bold" });
document.querySelector("#lock").innerHTML = toSvg(lock, { size: 24, color: "#1265ec" });

Customising Icons

Every icon takes the same options for size, style, colour and stroke weight.

Options
// Size
toSvg(home, { size: 16 })
toSvg(home, { size: 32 })

// Style
toSvg(star)                       // linear (default)
toSvg(star, { variant: "bold" })
toSvg(star, { variant: "duotone" })

// Colour
toSvg(heart, { color: "#ff383c" })

// Stroke weight (line styles)
toSvg(home, { strokeWidth: 1 })

Direct Imports

Each icon also lives in its own module, named after its slug. Importing from there keeps only that one icon in your bundle, even without tree-shaking.

Direct import
import { home } from "fmicon/icons/home";
import { lock } from "fmicon/icons/lock";

Tip: Named imports from the main entry are tree-shaken by Vite, webpack and Rollup too. Direct imports are a guarantee for setups that don't tree-shake.

Options

Everything toSvg accepts.

PropTypeDefaultDescription
sizenumber | string24Width and height in pixels
variant"linear" | "outline" | "bold" | …"linear"Any of the 8 styles, plus "glass-light"
colorstringcurrentColorAny CSS colour; glass keeps its own
strokeWidthnumber | string1.5Line weight for linear, twotone, broken and duotone
titlestring–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"linear"
Outline"outline"
Bold"bold"
Bulk"bulk"
Twotone"twotone"
Broken"broken"
Glass"glass"
Duotone"duotone"
Using styles
toSvg(home)  // linear
toSvg(home, { variant: "bold" })
toSvg(home, { variant: "glass" })
toSvg(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
Colour
// Inherits the colour of #toolbar
document.querySelector("#toolbar").style.color = "#1265ec";

toSvg(home, { color: "#1265ec" })
toSvg(home, { color: "var(--brand)" })

Tip: Glass icons keep their own colours, so color doesn't change them. Use glass-light on light backgrounds.

Accessibility

SVGs from toSvg are hidden from screen readers unless you pass a title, which adds a <title> and role="img".

Accessible icon
button.innerHTML = toSvg(trash, { size: 20 });
button.setAttribute("aria-label", "Delete item");

// An icon that carries meaning on its own
status.innerHTML = toSvg(warning2, { size: 20, 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.

Imports
// Good: only these icons end up in the bundle
import { home, lock, toSvg } from "fmicon";

// Avoid: pulls in all 891 icons
import * as Icons from "fmicon";
MethodBundle impactBest for
fmicon-react, /vue, /react-nativeOnly the icons you importApps with a bundler
…/icons/<slug>Exactly one icon per importSetups without tree-shaking
fmicon + toSvgOnly the icons you importVanilla JS, web components
CDN <img>Nothing in the bundleStatic sites, prototypes, email

TypeScript

Types ship with every package. Icon names autocomplete, and so do the styles.

Types
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.

Icon name not found
// Data exports are camelCase; reserved words get "Icon"
import { arrowCircleRight, exportIcon } from "fmicon";
Colour not changing
// Glass keeps its own colours; pick another style
toSvg(home, { variant: "bold", color: "#1265ec" })
Stroke weight has no effect
// strokeWidth only applies to linear, twotone, broken and duotone
toSvg(home, { variant: "linear", strokeWidth: 2 })