2021-10-01 09:19:36 +02:00
---
title: Lucide Preact
---
# Lucide Preact
Implementation of the lucide icon library for preact applications.
## Installation
2023-06-12 22:10:15 +02:00
::: code-group
```sh [pnpm]
pnpm install lucide-preact
2022-10-27 08:19:45 +02:00
```
2021-10-01 09:19:36 +02:00
2023-06-12 22:10:15 +02:00
```sh [yarn]
yarn add lucide-preact
```
2021-10-01 09:19:36 +02:00
2023-06-12 22:10:15 +02:00
```sh [npm]
2021-10-01 09:19:36 +02:00
npm install lucide-preact
```
2024-11-29 09:11:30 +01:00
```sh [bun]
bun add lucide-preact
```
2023-06-12 22:10:15 +02:00
:::
2021-10-01 09:19:36 +02:00
## How to use
2023-09-02 13:48:45 -06:00
Lucide is built with ES Modules, so it's completely tree-shakable.
2023-06-12 22:10:15 +02:00
2023-09-02 13:48:45 -06:00
Each icon can be imported as a Preact component, which renders an inline SVG element. This way, only the icons that are imported into your project are included in the final bundle. The rest of the icons are tree-shaken away.
2021-10-01 09:19:36 +02:00
### Example
2023-06-12 22:10:15 +02:00
Additional props can be passed to adjust the icon:
2021-10-01 09:19:36 +02:00
2023-06-12 22:10:15 +02:00
```jsx
2021-10-01 09:19:36 +02:00
import { Camera } from 'lucide-preact';
// Usage
const App = () => {
2022-10-27 08:19:45 +02:00
return <Camera color="red" size={48} />;
2021-10-01 09:19:36 +02:00
};
export default App;
```
2023-06-12 22:10:15 +02:00
## Props
2021-10-01 09:19:36 +02:00
2023-04-20 16:08:34 +02:00
| name | type | default |
| --------------------- | --------- | ------------ |
| `size` | * number * | 24 |
| `color` | * string * | currentColor |
| `strokeWidth` | * number * | 2 |
| `absoluteStrokeWidth` | * boolean * | false |
2021-10-01 09:19:36 +02:00
2023-06-12 22:10:15 +02:00
### Applying props
2021-10-01 09:19:36 +02:00
2023-09-02 13:48:45 -06:00
To customize the appearance of an icon, you can pass custom properties as props directly to the component. The component accepts all SVG attributes as props, which allows flexible styling of the SVG elements. See the list of SVG Presentation Attributes on [MDN ](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/Presentation ).
2021-10-01 09:19:36 +02:00
2023-06-12 22:10:15 +02:00
```jsx
2021-10-01 09:19:36 +02:00
// Usage
const App = () => {
2022-10-27 08:19:45 +02:00
return <Camera fill="red" stroke-linejoin="bevel" />;
2021-10-01 09:19:36 +02:00
};
```
2023-06-12 22:10:15 +02:00
> SVG attributes in Preact aren't transformed, so if you want to change for example the `stroke-linejoin` you need to pass it in kebabcase. Basically how the SVG spec want you to write it. See this topic in the [Preact documentation](https://preactjs.com/guide/v10/differences-to-react/#svg-inside-jsx).
2021-10-01 09:19:36 +02:00
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 by using the `Icon` component.
All props like regular lucide icons can be passed to adjust the icon appearance.
### Using the `Icon` component
This creates a single icon based on the iconNode passed and renders a Lucide icon component.
```jsx
import { Icon } from 'lucide-preact';
2025-05-03 09:28:29 +02:00
import { coconut } from '@lucide/lab ';
2024-04-26 17:59:04 +02:00
const App = () => (
2025-05-03 09:28:29 +02:00
<Icon iconNode={coconut} />
2024-04-26 17:59:04 +02:00
);
```
2023-06-12 22:10:15 +02:00
## One generic icon component
2021-10-01 09:19:36 +02:00
2023-09-02 13:48:45 -06:00
It is possible to create one generic icon component to load icons, but it is not recommended.
2021-10-01 09:19:36 +02:00
2023-06-12 22:10:15 +02:00
::: danger
2023-09-02 13:48:45 -06:00
The example below imports all ES Modules, so exercise caution when using it. Importing all icons will significantly increase the build size of the application, negatively affecting its performance. This is especially important when using bundlers like `Webpack` , `Rollup` , or `Vite` .
2023-06-12 22:10:15 +02:00
:::
2021-10-01 09:19:36 +02:00
2023-06-12 22:10:15 +02:00
### Icon Component Example
2021-10-01 09:19:36 +02:00
2023-06-12 22:10:15 +02:00
```jsx
import { icons } from 'lucide-preact';
2021-10-01 09:19:36 +02:00
2022-10-27 08:19:45 +02:00
const Icon = ({ name, color, size }) => {
2021-10-01 09:19:36 +02:00
const LucideIcon = icons[name];
2022-10-27 08:19:45 +02:00
return <LucideIcon color={color} size={size} />;
2021-10-01 09:19:36 +02:00
};
export default Icon;
```
2023-06-12 22:10:15 +02:00
#### Using the Icon Component
```jsx
import Icon from './Icon';
const App = () => {
2025-05-03 09:28:29 +02:00
return <Icon name="house" />;
2023-06-12 22:10:15 +02:00
};
export default App;
```