Features
- 504 icons that share one 24 × 24 grid and one line weight, in categories from arrows and files to
social logos and charts, and 935 aliases for the names you would guess (
tick and done are
check).
- Plain strings.
renderIconSvg returns an <svg> string, so it works in the browser, in Node (the server, a build
script, an email template) and in any framework. iconToDataUri gives the same icon for an <img> or a CSS background.
- Outline, solid and duotone, three weights, any size and colour, rotate, flip and right-to-left mirroring. Strokes
stay crisp: they are the same width in pixels at every size.
- Accessible by default. An icon is hidden from screen readers unless you give it a title or a label.
- Search built in.
searchIcons ranks by name, alias, tag and category: an icon picker in a few lines.
- Extensible. Register your own icons, and they work everywhere the built-in ones do.
- Typed names. Names autocomplete, and
IconName turns a typo in your own configuration into a compile error.
- Written in TypeScript, with no dependencies. The whole catalog is about 48 KB gzipped; import icons one by one from
@editora/icons/glyphs to ship only those (about 2 KB for the first).
- For React, use
@editora/react-icons, which is built on this
package.
Install
npm install @editora/icons
Quick start
A page with no build step loads the module from a CDN:
<style>
.toolbar { display: flex; gap: 6px; }
.toolbar button { display: grid; place-items: center; width: 36px; height: 36px; margin: 0; padding: 0; border: 1px solid #d0d7de; border-radius: 8px; background: #fff; color: #24292f; cursor: pointer; }
.toolbar button:hover { background: #f3f4f6; }
</style>
<div class="toolbar" id="toolbar"></div>
<script type="module">
import { renderIconSvg } from 'https://cdn.jsdelivr.net/npm/@editora/icons/dist/index.esm.js';
const actions = { bold: 'Bold', italic: 'Italic', underline: 'Underline', link: 'Insert link', image: 'Insert image', undo: 'Undo' };
// The button is labelled, so the icon inside it is decorative (the default when it has no title).
document.getElementById('toolbar').innerHTML = Object.entries(actions)
.map(([icon, label]) => `<button type="button" aria-label="${label}">${renderIconSvg(icon, { size: 18 })}</button>`)
.join('');
</script>
With a bundler, import { renderIconSvg } from '@editora/icons' does the same. Icons are drawn 15 pixels wide unless you
ask for a size, and they take the text colour of the element they are in (currentColor), so they follow the button's
hover and dark-mode colours without any extra work.
Find an icon
searchIcons(query) finds icons the way a person looks for them, best match first: by name (calendar), by alias
(delete finds trash), by tag (bin finds trash, ai finds sparkles) and by category (weather). Every word
of the query has to match ("arrow left"); when no icon matches them all, the ones that match the most words come back
instead of nothing. Each result says what matched, so a picker can show "trash · bin". { category } searches one
category (or several), { limit } caps the list, and an empty query lists every icon. listIconCategories() gives the
categories and their sizes, for the filters of a picker. Icons you register are searched too.
listIcons() has every name, hasIcon(name) tells you whether one exists and listIconAliases() maps each alias to
its icon. A name is matched without regard to case, and spaces and underscores count as dashes: Chart Line,
chart_line and chart-line are the same icon. renderIconSvg returns an empty string for a name it does not know, so
a typo draws nothing rather than throwing.
In TypeScript the names autocomplete. Every function that takes a name accepts an IconName (one of the built-in names)
or any other string, since an alias or an icon you registered is a name too. To have a typo caught when you compile,
type your own names as IconName:
import { renderIconSvg, type IconName } from '@editora/icons';
const menu: Array<{ label: string; icon: IconName }> = [
{ label: 'Orders', icon: 'order' },
{ label: 'Settings', icon: 'settings' },
// { label: 'Reports', icon: 'reprot' }, // error: Type '"reprot"' is not assignable to type 'IconName'. Did you mean '"report"'?
];
const html = menu.map((item) => `${renderIconSvg(item.icon)} ${item.label}`);
IconName lists the built-in names only, not their aliases (check, not tick).
import { listIconCategories, renderIconSvg, searchIcons } from '@editora/icons';
const root = document.getElementById('editor')!;
root.innerHTML = `
<style>
.catalog .bar { display: flex; gap: 8px; }
.catalog input, .catalog select { box-sizing: border-box; padding: 10px 14px; border: 1px solid #d0d7de; border-radius: 8px; font: 15px system-ui, sans-serif; background: #fff; }
.catalog input { flex: 1; min-width: 0; }
.catalog .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(136px, 1fr)); grid-auto-rows: 76px; gap: 8px; max-height: 328px; margin-top: 12px; overflow: auto; }
.catalog .cell { display: grid; justify-items: center; align-content: center; gap: 8px; min-width: 0; border-radius: 8px; color: #24292f; background: #f6f8fa; font: 11px ui-monospace, monospace; }
.catalog .cell span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
</style>
<div class="catalog">
<div class="bar">
<input type="search" placeholder="Search icons" aria-label="Search icons" />
<select aria-label="Category">
<option value="">All categories</option>
${listIconCategories().map(({ name, count }) => `<option value="${name}">${name} (${count})</option>`).join('')}
</select>
</div>
<div class="grid"></div>
</div>`;
const input = root.querySelector('input')!;
const select = root.querySelector('select')!;
const grid = root.querySelector('.grid')!;
const show = () => {
const results = searchIcons(input.value, { category: select.value || undefined });
grid.innerHTML = results
.map(({ name, matchedBy, matched }) => {
// "trash · bin": say why an icon whose name does not contain the query is here.
const label = matchedBy === 'name' ? name : `${name} · ${matched}`;
return `<div class="cell" title="${label}">${renderIconSvg(name, { size: 28 })}<span>${label}</span></div>`;
})
.join('');
};
input.addEventListener('input', show);
select.addEventListener('change', show);
show();
Style an icon
import { renderIconSvg, type IconRenderOptions } from '@editora/icons';
const samples: Array<[label: string, name: string, options: IconRenderOptions]> = [
['default', 'bell', {}],
['size: 40', 'bell', { size: 40 }],
['color', 'bell', { size: 40, color: '#2563eb' }],
['iconWeight: thin', 'bell', { size: 40, iconWeight: 'thin' }],
['iconWeight: bold', 'bell', { size: 40, iconWeight: 'bold' }],
['strokeWidth: 2.5', 'bell', { size: 40, strokeWidth: 2.5 }],
['variant: solid', 'bell', { size: 40, variant: 'solid', color: '#2563eb' }],
['variant: duotone', 'shield', { size: 40, variant: 'duotone', color: '#2563eb', secondaryColor: '#93c5fd' }],
['arrow-right', 'arrow-right', { size: 40 }],
['rotate: 90', 'arrow-right', { size: 40, rotate: 90 }],
['flip: horizontal', 'arrow-right', { size: 40, flip: 'horizontal' }],
['rtl: true', 'arrow-right', { size: 40, rtl: true }],
];
document.getElementById('editor')!.innerHTML = `
<style>
.samples { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; }
.samples figure { display: grid; grid-template-rows: 40px auto; justify-items: center; align-items: center; gap: 12px; margin: 0; padding: 16px 8px 12px; border: 1px solid #d0d7de; border-radius: 10px; color: #24292f; }
.samples figcaption { font: 12px ui-monospace, monospace; color: #57606a; }
</style>
<div class="samples">
${samples.map(([label, name, options]) => `<figure>${renderIconSvg(name, options)}<figcaption>${label}</figcaption></figure>`).join('')}
</div>`;
Every option of renderIconSvg(name, options) and iconToDataUri(name, options):
| Option |
Type |
Default |
Notes |
variant |
'outline' \| 'solid' \| 'duotone' |
'outline' |
Falls back to outline when the icon has no such variant. |
size |
number \| string |
15 |
Width and height: a number of pixels, or a CSS length such as '1.5rem'. Anything else is ignored. |
color |
string |
'currentColor' |
The icon's colour. |
secondaryColor |
string |
color |
The second colour of a duotone icon. |
iconWeight |
'thin' \| 'regular' \| 'bold' |
'regular' |
Stroke width 1.25, 1.5 or 1.75. |
strokeWidth |
number |
1.5 |
Stroke width in pixels. Wins over iconWeight; a negative or non-numeric value is ignored. |
strokeLinecap |
'butt' \| 'round' \| 'square' |
'round' |
The ends of lines. |
strokeLinejoin |
'miter' \| 'round' \| 'bevel' |
'round' |
The corners of lines. |
title |
string |
none |
Adds a <title> and makes the icon an image with that name. |
ariaLabel |
string |
none |
Makes the icon an image with that name, without a <title>. |
decorative |
boolean |
true unless there is a title or ariaLabel |
true hides the icon from screen readers. |
rotate |
number |
0 |
Degrees, clockwise. |
flip |
'horizontal' \| 'vertical' \| 'both' |
none |
Mirrors the icon. |
rtl |
boolean |
false |
Mirrors the icons that point a direction (12 of them: arrows, chevrons, carets, reply), and no others. |
className, style |
string |
none |
Set on the <svg>. |
attrs |
Record<string, string \| number \| boolean \| undefined> |
none |
More attributes for the <svg>, such as data-*. A name that could break out of the markup, or that starts with on, is dropped; values are escaped. |
absoluteStrokeWidth |
boolean |
none |
Does nothing: strokes are already the same width on screen at every size. |
Variants
Every icon has an outline. Solid and duotone are drawn for few of them: 28 have a solid variant
(check, x, bell, heart, star, home, lock, trash, folder... ) and 2 have a duotone one
(chart-pie and shield). Asking for a variant an icon does not have draws
its outline, and resolveIcon(name, variant) tells you which one you got.
Accessibility
An icon without a title or a label is decorative: aria-hidden="true" and role="presentation". That is right for an
icon next to text, or inside a button that has its own label, as in the toolbar above. An icon that is the only thing
saying what a control does needs a name:
renderIconSvg('bell', { title: 'Notifications' }); // role="img" aria-label="Notifications", plus a <title>
renderIconSvg('bell', { ariaLabel: 'Notifications' }); // the same, without the <title> (no tooltip)
renderIconSvg('bell', { decorative: false }); // role="img" aria-label="bell": the icon's own name
renderIconSvg('bell', { title: 'Notifications', decorative: true }); // hidden, whatever the title
Your own icons
An icon is a name, an optional list of aliases and a list of shapes. Shapes without a stroke or a fill are drawn as an
outline in the icon's colour, so a few paths are enough. Once registered, an icon is found by renderIconSvg,
hasIcon and listIcons like the built-in ones. Registering a name that exists replaces that icon.