Health icons for JavaScript
Health icons for any website: put placeholders in your HTML and they become icons. Or make icons in code, as SVG text or elements.
Getting started
Install the package
In your project’s folder, run this command. Using Yarn or pnpm? Run
yarn add @healthicons/coreorpnpm add @healthicons/coreinstead.npm install @healthicons/coreFind an icon
Browse the icons and click one you like. The window that opens shows its Filename, like
blood-bag, which you use in your HTML, and its Code name, likeBloodBag, which you use in your JavaScript.Put placeholders in your HTML
Add an
<i>tag where each icon should go, with the icon’s name from this site (with dashes, likeblood-bag).<i data-healthicon="blood-bag"></i>Turn them into icons
In your JavaScript, import the icons you use (in PascalCase) and call
createIcons. It replaces each placeholder with its icon.import { createIcons, BloodBag } from '@healthicons/core'; createIcons({ icons: { BloodBag } });ResultChange how it looks
Icons are outlined and 24 pixels by default, in the color of the text around them. Change any of these on the placeholder.
<i data-healthicon="blood-bag" data-variant="filled" data-size="48" data-color="#6666ff" ></i>Result
Using AI?
Copy our prompt for AI assistants before asking ChatGPT, Claude, Copilot or another assistant to add icons, so it uses the package correctly.
Examples
Without installing anything
No build tools? Load the package from a CDN instead of step 1. This loads every icon, so it’s best for small sites and trying things out.
<i data-healthicon="heart"></i>
<script type="module">
import { createIcons, icons } from
'https://cdn.jsdelivr.net/npm/@healthicons/core/+esm';
createIcons({ icons });
</script>As SVG text
toSvg gives an icon’s <svg> as text, to add to HTML you’re building.
import { toSvg, BloodBag } from '@healthicons/core';
const svg = toSvg(BloodBag, { variant: 'filled', size: 32 });As an element
createElement gives an <svg> element to add to the page.
import { createElement, BloodBag } from '@healthicons/core';
document.body.append(createElement(BloodBag, { title: 'Blood bag' }));Options
On placeholders, set these as data- attributes (data-variant="filled"); with toSvg and createElement, as options. Other attributes, like a class, are added to the icon’s <svg> element.
| Option | Default | What it does |
|---|---|---|
variant | outline | The style: outline or filled |
size | 24 | Width and height, in pixels or any CSS size (like 1.5em). At 24 pixels and smaller, icons that have a version drawn for small sizes use it. |
color | The text color | Any CSS color |
title | None | Shown as a tooltip and read out by screen readers. Without a title (or an aria-label), icons are hidden from screen readers. |
Icon names
The easiest way to get an icon’s name is from the icon itself: open it in the icon library and copy its Code name. For placeholders, use its Filename instead, like blood-bag.
Code names follow a pattern: they’re the filename in PascalCase, so blood-bag is BloodBag and blister-pills_oval_x14 is BlisterPillsOvalX14. A few filenames can’t be written that way, so they use the icon’s title: 0 to 9 are Number0 to Number9, ! is ExclamationPoint and 4x4 is SUV.
If your editor suggests names as you type (most do), start typing what you’re looking for after the { in your import to see the matching icons.