2021-10-01 09:19:36 +02:00
# Lucide
2025-10-24 05:18:51 -07:00
The core Lucide package for vanilla JavaScript applications. This package allows you to easily add scalable vector icons to any web project without framework dependencies. Perfect for static websites, legacy applications, or when you need lightweight icon integration with maximum browser compatibility.
**What you can accomplish:**
- Add icons to HTML using simple data attributes
- Dynamically create and insert SVG icons with JavaScript
- Customize icon appearance with CSS classes and inline styles
- Tree-shake unused icons to keep bundle sizes minimal
- Use icons in any JavaScript environment or plain HTML
2021-10-01 09:19:36 +02:00
## Installation
### Package Managers
2023-06-12 22:10:15 +02:00
::: code-group
2022-10-27 08:19:45 +02:00
2023-06-12 22:10:15 +02:00
```sh [pnpm]
2025-10-26 17:01:12 +01:00
pnpm add lucide
2023-06-12 22:10:15 +02:00
```
2022-10-27 08:19:45 +02:00
2023-06-12 22:10:15 +02:00
```sh [yarn]
2021-10-01 09:19:36 +02:00
yarn add lucide
```
2023-06-12 22:10:15 +02:00
```sh [npm]
npm install lucide
```
2024-11-29 09:11:30 +01:00
```sh [bun]
bun add lucide
```
2023-06-12 22:10:15 +02:00
:::
2021-10-01 09:19:36 +02:00
### CDN
2022-10-27 08:19:45 +02:00
```html
2021-10-01 09:19:36 +02:00
<!-- Development version -->
<script src="https://unpkg.com/lucide@latest/dist/umd/lucide .js"></script>
<!-- Production version -->
<script src="https://unpkg.com/lucide@latest "></script>
```
## Usage
### With unpkg
Here is a complete example with unpkg
```html
<!DOCTYPE html>
<body>
2023-06-12 22:10:15 +02:00
<i data-lucide="volume-2" class="my-class"></i>
<i data-lucide="x"></i>
<i data-lucide="menu"></i>
2021-10-01 09:19:36 +02:00
<script src="https://unpkg.com/lucide@latest "></script>
<script>
lucide.createIcons();
</script>
</body>
```
### With ESModules
2022-10-03 16:36:33 +02:00
To reduce bundle size, lucide is built to be fully tree-shakable.
2023-06-12 22:10:15 +02:00
The `createIcons` function will search for HTMLElements with the attribute `data-lucide` and replace it with the svg from the given icon name.
2021-10-01 09:19:36 +02:00
```html
<!-- Your HTML file -->
2023-06-12 22:10:15 +02:00
<i data-lucide="menu"></i>
2021-10-01 09:19:36 +02:00
```
```js
import { createIcons, icons } from 'lucide';
// Caution, this will import all the icons and bundle them.
2022-10-27 08:19:45 +02:00
createIcons({ icons });
2021-10-01 09:19:36 +02:00
// Recommended way, to include only the icons you need.
import { createIcons, Menu, ArrowRight, Globe } from 'lucide';
createIcons({
icons: {
Menu,
ArrowRight,
2022-10-27 08:19:45 +02:00
Globe
}
2021-10-01 09:19:36 +02:00
});
```
2023-06-12 22:10:15 +02:00
## Advanced Usage
### Additional Options
2021-10-01 09:19:36 +02:00
2025-08-18 15:25:08 +02:00
In the `createIcons` function you can pass some extra parameters:
- you can pass `nameAttr` to adjust the attribute name to replace for
- you can pass `attrs` to pass additional custom attributes, for instance CSS classes or stroke options.
- you can pass `root` to provide a custom DOM element the icons should be replaced in (useful when manipulating small sections of a large DOM or elements in the shadow DOM)
2025-10-17 12:46:55 +03:00
- you can pass `inTemplates: true` to also replace icons inside `<template>` tags.
2021-10-01 09:19:36 +02:00
Here is a full example:
```js
import { createIcons } from 'lucide';
createIcons({
attrs: {
class: ['my-custom-class', 'icon'],
'stroke-width': 1,
2022-10-27 08:19:45 +02:00
stroke: '#333 '
2021-10-01 09:19:36 +02:00
},
2025-08-18 15:25:08 +02:00
nameAttr: 'data-lucide', // attribute for the icon name.
root: element, // DOM element to replace icons in.
2025-10-17 12:46:55 +03:00
inTemplates: true // Also replace icons inside <template> tags.
2021-10-01 09:19:36 +02:00
});
```
2023-06-12 22:10:15 +02:00
### Treeshake the library, only use the icons you use
2021-10-01 09:19:36 +02:00
```js
import { createIcons, Menu, ArrowRight, Globe } from 'lucide';
createIcons({
icons: {
Menu,
ArrowRight,
2022-10-27 08:19:45 +02:00
Globe
}
2021-10-01 09:19:36 +02:00
});
```
2025-10-17 12:46:55 +03:00
### Custom Document root
Apply icons in a custom root element, for instance a shadow DOM root.
```js
import { createIcons } from 'lucide';
// Custom root element, for instance a shadow DOM root.
const shadowRoot = element.attachShadow({ mode: 'open' });
createIcons({
root: shadowRoot
});
```
### Apply icons inside `<template>` tags
By default icons inside `<template>` tags are not added.
By setting the `inTemplates` option to `true` , icons inside templates will also be replaced.
```js
import { createIcons } from 'lucide';
createIcons({
inTemplates: true
});
```
2023-06-12 22:10:15 +02:00
### Custom Element binding
2021-10-01 09:19:36 +02:00
```js
import { createElement, Menu } from 'lucide';
const menuIcon = createElement(Menu); // Returns HTMLElement (svg)
2025-02-24 10:10:28 +01:00
// Append HTMLElement in the DOM
const myApp = document.getElementById('app');
myApp.appendChild(menuIcon);
```
#### Custom Element binding with custom attributes
```js
import { createElement, Menu } from 'lucide';
const menuIcon = createElement(Menu, {
class: ['my-custom-class', 'icon'],
'stroke-width': 1,
stroke: '#333 '
}); // Returns HTMLElement (svg)
2021-10-01 09:19:36 +02:00
2025-02-24 10:10:28 +01:00
// Append HTMLElement in the DOM
2021-10-01 09:19:36 +02:00
const myApp = document.getElementById('app');
myApp.appendChild(menuIcon);
```
2024-04-26 17:59:04 +02:00
### With Lucide lab or custom icons
[Lucide lab ](https://github.com/lucide-icons/lucide-lab ) is a collection of icons that are not part of the Lucide main library.
They can be used in the same way as the official icons.
```js
2025-05-03 09:28:29 +02:00
import { coconut } from '@lucide/lab ';
2024-04-26 17:59:04 +02:00
createIcons({
icons: {
2025-05-03 09:28:29 +02:00
coconut
2024-04-26 17:59:04 +02:00
}
});
```