Implementation of the lucide icon library for web applications.
npm install lucide#oryarn add lucide
<!-- Development version --><script src="https://unpkg.com/lucide@latest/dist/umd/lucide.js"></script><!-- Production version --><script src="https://unpkg.com/lucide@latest"></script>
Here is a complete example with unpkg
<!DOCTYPE html><body><i icon-name="volume-2" class="my-class"></i><i icon-name="x"></i><i icon-name="menu"></i><script src="https://unpkg.com/lucide@latest"></script><script>lucide.createIcons();</script></body>
To reduce bundle size, lucide is built to be fully treeshakable.
The createIcons
function will search for HTMLElements with the attribute icon-name
and replace it with the svg from the given icon name.
<!-- Your HTML file --><i icon-name="menu"></i>
import { createIcons, icons } from 'lucide';// Caution, this will import all the icons and bundle them.createIcons({icons});// Recommended way, to include only the icons you need.import { createIcons, Menu, ArrowRight, Globe } from 'lucide';createIcons({icons: {Menu,ArrowRight,Globe,},});
In the createIcons
function you can pass some extra parameters to adjust the nameAttr
or add custom attributes like for example classes.
Here is a full example:
import { createIcons } from 'lucide';createIcons({attrs: {class: ['my-custom-class', 'icon'],'stroke-width': 1,stroke: '#333',},nameAttr: 'icon-name', // attribute for the icon name.});
import { createIcons, Menu, ArrowRight, Globe } from 'lucide';createIcons({icons: {Menu,ArrowRight,Globe,},});
import { createElement, Menu } from 'lucide';const menuIcon = createElement(Menu); // Returns HTMLElement (svg)// set custom attributes with browser native functionsmenuIcon.setAttribute('stroke', '#333');menuIcon.classList.add('my-icon-class');// Append HTMLElement in webpageconst myApp = document.getElementById('app');myApp.appendChild(menuIcon);