mirror of
https://github.com/lucide-icons/lucide.git
synced 2026-07-10 20:58:46 +02:00
69 lines
2.0 KiB
Markdown
69 lines
2.0 KiB
Markdown
|
|
---
|
||
|
|
title: Stroke width - React
|
||
|
|
description: Learn how to adjust the stroke width of icons in your React application using the `strokeWidth` prop or adjust the strokeWidth appearance using the `absoluteStrokeWidth` prop.
|
||
|
|
---
|
||
|
|
<script setup>
|
||
|
|
import Sandpack from '~/.vitepress/theme/components/editors/Sandpack.vue'
|
||
|
|
</script>
|
||
|
|
|
||
|
|
# Stroke width
|
||
|
|
|
||
|
|
All icons are designed with SVG elements using strokes.
|
||
|
|
These have a default stroke width of `2px`.
|
||
|
|
|
||
|
|
The `strokeWidth` can be adjusted to create a different look of the icons.
|
||
|
|
|
||
|
|
## Adjusting stroke width with `strokeWidth` prop
|
||
|
|
|
||
|
|
::: sandpack {template=react showTabs=false editorHeight=300 editorWidthPercentage=60 dependencies="lucide-react"}
|
||
|
|
|
||
|
|
```jsx App.js [active]
|
||
|
|
import { FolderLock } from "lucide-react";
|
||
|
|
|
||
|
|
function App() {
|
||
|
|
return (
|
||
|
|
<div className="app">
|
||
|
|
<FolderLock strokeWidth={1} />
|
||
|
|
</div>
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
export default App;
|
||
|
|
```
|
||
|
|
:::
|
||
|
|
|
||
|
|
|
||
|
|
## Absolute stroke width
|
||
|
|
|
||
|
|
When adjusting the `size` prop the size of the stroke width will be relative to the size of the icon, this is the default SVG behavior. The `absoluteStrokeWidth` prop is introduced to adjust this behavior to make the stroke width constant no matter the size of the icon.
|
||
|
|
|
||
|
|
This means that when `absoluteStrokeWidth` is enabled and the `size` of the icons is set to `48px` the `strokeWidth` will still be `2px` on the screen.
|
||
|
|
|
||
|
|
Note `2px` is the default stroke width for a Lucide icon, this can be adjusted to all sizes.
|
||
|
|
|
||
|
|

|
||
|
|
|
||
|
|
### Adjusting stroke width with `absoluteStrokeWidth` prop
|
||
|
|
|
||
|
|
Setting `absoluteStrokeWidth` to `true` will make the stroke width absolute.
|
||
|
|
|
||
|
|
::: sandpack {template=react showTabs=false editorHeight=320 editorWidthPercentage=60 dependencies="lucide-react"}
|
||
|
|
|
||
|
|
```jsx App.js [active]
|
||
|
|
import { RollerCoaster } from "lucide-react";
|
||
|
|
|
||
|
|
function App() {
|
||
|
|
return (
|
||
|
|
<div className="app">
|
||
|
|
<RollerCoaster
|
||
|
|
size={96}
|
||
|
|
absoluteStrokeWidth={true}
|
||
|
|
/>
|
||
|
|
</div>
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
export default App;
|
||
|
|
```
|
||
|
|
:::
|