Skip to content

Icons guide ​

@nervure/icons is a set of 134 animated SVG icons, apart from the charts. They are drawn by hand on a 24 × 24 grid, with a 2 px stroke and round ends. Each one draws itself in, then plays a motion of its own: the bell rings, the heart beats, the refresh arrows turn, the download arrow drops, the wind blows, the battery fills. See them all.

Install ​

bash
npm install @nervure/icons

No dependency. React and Vue are optional peers, used only by their own entries.

EntryWhat it gives
@nervure/iconsicon(), iconSvg(), every icon by name, iconCss, play()
@nervure/icons/corethe same functions without any icon, to import icons one by one
@nervure/icons/icons/<name>one icon (@nervure/icons/icons/bell exports bell)
@nervure/icons/elementthe <nv-icon> web component
@nervure/icons/react<Icon>
@nervure/icons/vue<NvIcon>
@nervure/icons/cdn/nervure-icons.min.jsone file for a <script> tag: <nv-icon> and window.nervureIcons
@nervure/icons/svg/<name>.svg, svg/duo/<name>.svgstatic files, for design tools

Plain JavaScript ​

js
import { icon, iconSvg } from '@nervure/icons';

// An <svg> element
document.querySelector('#bell').append(icon('bell', { animate: 'hover', size: 20 }));

// Markup, on the server or in a template
const html = iconSvg('heart', { variant: 'duo', title: 'Like' });

icon() adds the animation stylesheet to the document the first time an animated icon is made. With iconSvg() nothing runs in the page: add iconCss once (in a <style>), or call injectStyles() in the browser, or pass css: true to put the stylesheet inside that one <svg>.

For the smallest bundle, import the core and the icons you use:

js
import { icon } from '@nervure/icons/core';
import { bell } from '@nervure/icons/icons/bell';

icon(bell, { animate: 'load' });

The main entry is tree-shakeable too for named icons (import { bell } from '@nervure/icons'), but icon('bell') by name keeps the whole set (about 8 kB of data gzipped).

Web component ​

html
<script type="module">
  import '@nervure/icons/element';
</script>

<nv-icon name="bell" animate="hover"></nv-icon>
<nv-icon name="heart" variant="duo" size="32" accent="#d1495b" label="Favourites"></nv-icon>

Attributes: name, size, color, accent, fill, variant, animate, stroke-width, label. The element draws in its light DOM, so the colour of the text and your CSS custom properties apply. element.play() plays the animation again.

Without a build tool, from a CDN (pin the version):

html
<script src="https://cdn.jsdelivr.net/npm/@nervure/icons@0.1.0/cdn/nervure-icons.min.js"></script>
<nv-icon name="download" animate="hover"></nv-icon>
<script>
  document.body.append(nervureIcons.icon('sun', { animate: 'loop' }));
</script>

React ​

jsx
import { Icon } from '@nervure/icons/react';

export function Save() {
  return (
    <button className="nv-icon-trigger">
      <Icon name="download" animate="hover" /> Save
    </button>
  );
}

Props: name (a name or an icon object), the options below, className, and any other <svg> prop (onClick, style, id…). It renders on the server; the stylesheet is added on mount.

Vue ​

vue
<script setup>
import { NvIcon } from '@nervure/icons/vue';
</script>

<template>
  <NvIcon name="bell" animate="hover" :size="20" />
</template>

Options ​

OptionDefault
size24pixels, or any CSS length ('1em')
strokeWidth2in grid units: 1.5 reads better at 16 px and below, 2.5 at 64 px and above
colorcurrentColorcolour of the strokes
variant'mono''mono' or 'duo'
accentnervure green #2a9d8fmarks of the duo colouring (--nv-icon-accent)
fillthe accent at 28 %areas of the duo colouring (--nv-icon-fill)
animate'none''none', 'load', 'hover', 'loop' or 'click'
titlenoneaccessible name
classextra classes on the <svg>

Animation ​

animateWhat happens
nonea still icon, no class or attribute for motion
loaddraws in when it appears, then plays its motion once
hoverplays its motion while the pointer is on the icon, or on any parent with the class nv-icon-trigger (a button, a link, a menu item)
clickplays its motion on each click on the icon or on a parent with nv-icon-trigger
loopdraws in, then plays its motion again and again, with a rest between two

The motions are CSS keyframes on stroke-dashoffset, transform and opacity: no JavaScript timer and no SMIL. Every motion ends where it started, so the resting icon is the last frame. play(svg) plays it again from code.

For loading, use loader or spinner with animate="loop": they turn without a rest.

Less motion ​

When the reader asks for less motion (prefers-reduced-motion: reduce), nothing moves: the stylesheet turns every animation off and icon() draws a still icon, already finished.

Colours ​

The strokes take currentColor: the icon follows the colour of the text. The duo colouring tints the areas and draws a few marks in a second colour. Set the colours once for a whole page or a part of it:

css
.toolbar {
  color: #30466b;
  --nv-icon-accent: #d1495b;
  --nv-icon-fill: #fde7ea;
}

Accessibility ​

An icon without title (or label on <nv-icon>) is decorative: aria-hidden="true", as it should be next to a text. Give a title when the icon stands alone, in a button without text for example: the <svg> gets role="img", an aria-label and a <title>.

js
icon('trash', { title: 'Delete the row' });

Size ​

Each icon module is under 1 kB as shipped; the renderer and its stylesheet are about 5 kB gzipped; the CDN file with every icon is about 13 kB gzipped. The test suite and npm run size in packages/icons keep these budgets. The main nervure bundle does not include the icons.

Draw your own ​

An icon is an object: a name, a family, tags, a motion and shapes written as strings on the 24 grid.

js
import { icon } from '@nervure/icons/core';

const ticket = {
  name: 'ticket',
  category: 'business',
  tags: ['event'],
  motion: 'swing',
  origin: '12 4',
  shapes: ['*~M4 7h16v3a2 2 0 0 0 0 4v3H4v-3a2 2 0 0 0 0-4z', '!M10 9v6'],
};
icon(ticket, { animate: 'hover' });

A shape is a path (M…), a circle (o cx cy r), a rectangle (r x y width height radius) or an ellipse (e cx cy rx ry), after optional flags: * area tinted in duo, ! mark in the accent colour, # solid shape, % faint, ~ part of the moving group, ^ moves on its own, after the previous one.