Reference
Attributes and props
| Attribute | React prop | Values | Default |
|---|---|---|---|
icon | icon | Icon name, set:icon | Required |
width, height | width, height | A number of pixels, a CSS length (2em, 1.5rem, 24px), or auto for the icon's own size | Height 1em, width in proportion |
color | color | Any CSS color | The text color |
stroke-width | strokeWidth | A positive number, in units of the icon's grid | The icon's own: 2 for Lucide and Tabler |
rotate | rotate | 90deg, 180deg, 270deg, or quarter turns 1, 2, 3 | No rotation |
flip | flip | horizontal, vertical, or both: horizontal,vertical | No flip |
inline | inline | Present or absent; true or false in React | Absent |
label | label | Text for screen readers | None: the icon is decorative |
placeholder | placeholder | skeleton, spinner or none | skeleton, or the value from configure() |
noobserver | — | Present or absent | Absent: an icon loads when it comes near the visible part of the page |
- Multicolor icons (Fluent Emoji Flat) keep their colors:
colorandstroke-widthdo not change them. - Rotation and flip are drawn inside the SVG, not with a CSS transform, so the icon's box follows the drawing: at 90° and 270° a non-square icon swaps its width and height. Flip is applied before rotation.
inlinelowers the icon by0.125em, so it sits on the text baseline like a letter.- Invalid values are ignored: the icon renders without that setting, and the console shows one warning with the allowed values.
- In React, sizes also take numbers (
width={32}), androtatealso takes the numbers1–3. The component always renders an<svg>, also while the icon loads, and other props such asclassName,style, event handlers andrefgo to it. - Color in React is an attribute of the
<svg>, so CSS that targets the<svg>itself, such as atext-*class inclassName, takes precedence over it. - With Tailwind CSS, its base styles make every
<svg>a block, so anIconsits on a line of its own. AddclassName="inline-block"to the icon, orsvg { display: inline-block; }to your base styles. The<iconavo-icon>tag is not affected.
Functions
@iconavo-ui/icon and @iconavo-ui/react export the same four functions and share one store of icons and settings for the whole page. Both also export the TypeScript types IconavoIconSet, IconavoIcon and IconavoAlias, the same as in the data packages.
configure(options)
function configure(options: {
api?: string[];
cdn?: string[];
placeholder?: "skeleton" | "spinner" | "none";
dev?: boolean;
}): void;| Option | What it sets | Default |
|---|---|---|
api | Hosts that answer batch requests, like the Iconify API | ["https://api.iconavo.dev"] |
cdn | Hosts with the static layout of cdn.iconavo.dev, one icon per request | ["https://cdn.iconavo.dev", "https://cdn2.iconavo.dev", "https://iconavo.b-cdn.net"] |
placeholder | What icons show while they load | "skeleton" |
dev | Development mode: a dashed frame in place of a missing icon | Detected, see Missing icons |
- A list replaces the default one, and
[]turns that kind of host off. - Options you leave out keep their values.
- A change applies to requests made after the call, so call
configure()before the first icon renders.
addIcons(data)
function addIcons(data: IconavoIconSet | IconavoIconSet[]): void;Adds icons in IconifyJSON format, one icon set per object. Added icons are never requested from the network. They replace icons with the same names, and icons already on the page redraw. It accepts:
- a batch from our API saved to a file, for example
https://api.iconavo.dev/lucide.json?icons=house,heart; iconsfrom the data packages@iconavo-ui/icons-{set}, which hold whole sets;- IconifyJSON from Iconify's
@iconify-json/*packages; - your own icons under your own prefix.
import { addIcons } from "@iconavo-ui/icon";
addIcons({
prefix: "acme",
width: 24,
height: 24,
icons: {
logo: { body: '<path fill="currentColor" d="M3 3h18v18H3z"/>' },
},
});<iconavo-icon icon="acme:logo"></iconavo-icon>A prefix follows the same rules as icon names; an invalid one throws an error. Names listed in not_found are remembered as missing.
loadIcons(names)
function loadIcons(names: string[]): Promise<IconavoIconSet[]>;Loads icons ahead of time: before a menu opens, or on the server for server rendering. It resolves with one IconifyJSON object per set, holding the loaded icons and, in not_found, the missing names.
It never rejects. It makes one pass over the hosts, at most 5 seconds, and leaves out icons that failed to load; components in the browser retry them later. An invalid name goes to not_found with a warning.
setLoader(prefix, loader)
function setLoader(
prefix: string,
loader: ((names: string[]) => Promise<IconavoIconSet | null>) | null,
): void;Loads one set from your own source instead of the hosts: a server with another format, a database, generated icons. It works for our sets too.
- The core calls
loaderwith the names it needs, in batches and without duplicates. - The result is added as with
addIcons. Names missing from it, or anullresult, count as missing icons. - A rejected promise, or one that does not settle within 5 seconds, counts as a failed host and is retried.
nullinstead of a function removes the loader.
import { setLoader } from "@iconavo-ui/icon";
setLoader("acme", async (names) => {
const response = await fetch(`/icons/acme.json?icons=${names.join(",")}`);
if (!response.ok) throw new Error(`Icons: HTTP ${response.status}`);
return response.json();
});IconavoProvider (React)
<IconavoProvider icons={icons}>{children}</IconavoProvider>Passes icons loaded on the server (IconavoIconSet[], as returned by loadIcons) to the components inside, for the server HTML and for hydration. See Next.js and server rendering.
Loading and errors
While an icon loads
- The icon keeps a
1em×1emsquare, or the size you set, so the text around it does not jump. With only one side set, the square has that side; withauto, it is1emuntil the icon's own size is known. - If loading takes longer than 150 ms, a placeholder appears: a skeleton by default, a spinner with
placeholder="spinner", nothing withplaceholder="none". When the system asks to reduce motion, placeholders do not animate. - The tag loads an icon when it comes within half a screen of the visible part of the page, so it is usually ready when you scroll to it;
noobserverturns this off. The React component loads it when it mounts. - Inside a scrolling container, and in an iframe from another site, such as a live example's preview, the half-screen margin does not apply: the tag loads an icon when it becomes visible.
- A tag that has never come near the visible part of the page prints empty. Add
noobserverto icons that must print. - In React, placeholders,
inlineand the development frame come from a stylesheet that the package adds when the page's scripts run. Until then, server-rendered HTML keeps an empty box of the icon's size, andinlineicons sit on the baseline.
Batches and hosts
- Icons requested at the same moment (in one tick of the event loop) go out together: one request per set, with sorted names, split into several requests when the address would be longer than 500 characters or hold more than 100 names. For example, 100 Lucide icons take 4 requests. An icon that is already loading is not requested again.
- The hosts are tried in order:
api.iconavo.devsends batches, thencdn.iconavo.dev,cdn2.iconavo.devandiconavo.b-cdn.netsend one icon per request, using theirmanifest.jsonto find the current version of a set. - If
api.iconavo.devdoes not answer within 1.5 seconds, the same icons are also requested from the static hosts. Static hosts send one icon per request, so the core waits longer before switching to them. Between hosts of the same kind (API hosts or static hosts), the wait is 750 ms. A host that fails outright is not waited for. The first answer wins. After 5 seconds without an answer, the attempt has failed. - A failed attempt is repeated after 1, 2 and 4 seconds while the icon is on the page, and the placeholder stays meanwhile. After the last attempt, the icon looks like a missing one and the console shows one warning with the error, but the icon is requested again the next time it appears.
Missing icons
- If a set has no such icon, its place stays empty, and the console shows one warning per name.
- A missing name is remembered and not requested again while the page is open.
- In development mode, a dashed frame marks the place. Development mode is on in the development build of your bundler (for example Vite or webpack) and, without a bundler, on pages opened from
localhost,127.0.0.1,[::1]or afile:address.configure({ dev: true })orconfigure({ dev: false })overrides it. - Names never break: renamed icons still answer to their old names, and icons that their authors removed still render.