`,// tags: ['cancel', 'close', 'delete', 'remove'], // attrs: { // class: 'feather feather-x', // xmlns: 'http://www.w3.org/2000/svg', // width: 24, // height: 24, // viewBox: '0 0 24 24', // fill: 'none', // stroke: 'currentColor', // 'stroke-width': 2, // 'stroke-linecap': 'round', // 'stroke-linejoin': 'round', // }, // toSvg: [Function], // } feather .icons .x .toSvg ( ) // feather .icons .x .toSvg ( { class : 'foo bar' , 'stroke-width' : 1 , color : 'red' } ) // ` ` `
See the
API Reference for more information about the available properties and methods of the
feather object.
SVG Sprite
1. Install
Note: If you intend to use Feather with a CDN, you can skip this installation step.
` ` ` sh npm install feather - icons -- save ` ` `
Or just copy [feather-sprite.svg ](https://unpkg.com/feather-icons/dist/feather-sprite.svg) into your project directory.
2. Use
Include an icon on your page with the following markup:
``` html <svg width="24" height="24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" > <use href = "path/to/feather-sprite.svg#circle" /> </svg > ```
Note: circle in the above example can be replaced with any valid icon name. See the complete list of icon names at feathericons.com .
However, this markup can be simplified using a simple CSS class to avoid repetition of SVG attributes between icons:
```css .feather { width : 24px ; height : 24px ; stroke : currentColor ; stroke-width : 2 ; stroke-linecap : round ; stroke-linejoin : round ; fill : none ; } ```
``` html <svg class = "feather" > <use href = "path/to/dist/feather-sprite.svg#circle" /> </svg > ```
Figma Feather is available as a
Figma component library . To use the components, log in to your Figma account and
duplicate the file to your drafts.
API Reference
feather.icons
An object with data about every icon.
Usage
` ` ` js feather .icons .x // { // name: 'x', // contents: ' ', // tags: ['cancel', 'close', 'delete', 'remove'], // attrs: { // class: 'feather feather-x', // xmlns: 'http://www.w3.org/2000/svg', // width: 24, // height: 24, // viewBox: '0 0 24 24', // fill: 'none', // stroke: 'currentColor', // 'stroke-width': 2, // 'stroke-linecap': 'round', // 'stroke-linejoin': 'round', // }, // toSvg: [Function], // } feather .icons .x .toString ( ) // ' ' ` ` `
Note: x in the above example can be replaced with any valid icon name. See the complete list of icon names at feathericons.com . Icons with multi-word names (e.g.arrow-right ) cannot be accessed using dot notation (e.g. feather.icons.x ). Instead, use bracket notation (e.g. feather.icons['arrow-right'] ).
feather.icons[name].toSvg([attrs])
Returns an SVG string.
Parameters
Name Type Description --------- ------ ----------- `attrs` Object Key-value
Hint: You might find these SVG attributes helpful for manipulating icons:
[color ](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/color)
[width ](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/width)
[height ](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/height)
[stroke-width ](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-width)
[stroke-linecap ](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-linecap)
[stroke-linejoin ](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-linejoin)
Usage
` ` ` js feather .icons .circle .toSvg ( ) // ' ' feather .icons .circle .toSvg ( { 'stroke-width' : 1 } ) // ' ' feather .icons .circle .toSvg ( { class : 'foo bar' } ) // ' ' ` ` `
feather.replace([attrs])
Replaces all elements that have a data-feather attribute with SVG markup corresponding to the element's data-feather attribute value.
Parameters
Name Type Description ---------- ------ ----------- `attrs` Object Key-value
Usage
Note: feather.replace() only works in a browser environment.
Simple usage:
``` html <i data-feather = "circle" > </i > <!-- <i > will be replaced with: <svg class = "feather feather-circle" xmlns = "http://www.w3.org/2000/svg" width = "24" height = "24" viewBox = "0 0 24 24" fill = "none" stroke = "currentColor" stroke-width = "2" stroke-linecap = "round" stroke-linejoin = "round" > <circle cx = "12" cy = "12" r = "10" > </circle > </svg > --> <script > feather.replace() </script > ```
You can pass feather.replace() an attrs object:
``` html <i data-feather = "circle" > </i > <!-- <i > will be replaced with: <svg class = "feather feather-circle foo bar" xmlns = "http://www.w3.org/2000/svg" width = "24" height = "24" viewBox = "0 0 24 24" fill = "none" stroke = "currentColor" stroke-width = "1" stroke-linecap = "round" stroke-linejoin = "round" > <circle cx = "12" cy = "12" r = "10" > </circle > </svg > --> <script > feather.replace({ class: 'foo bar', 'stroke-width': 1 }) </script > ```
All attributes on the placeholder element (i.e. ``) will be copied to the `` tag:
``` html <i data-feather = "circle" id = "my-circle" class = "foo bar" stroke-width = "1" > </i > <!-- <i > will be replaced with: <svg id = "my-circle" class = "feather feather-circle foo bar" xmlns = "http://www.w3.org/2000/svg" width = "24" height = "24" viewBox = "0 0 24 24" fill = "none" stroke = "currentColor" stroke-width = "1" stroke-linecap = "round" stroke-linejoin = "round" > <circle cx = "12" cy = "12" r = "10" > </circle > </svg > --> <script > feather.replace() </script > ```
(DEPRECATED) feather.toSvg(name, [attrs])
Note: feather.toSvg() is deprecated. Please use feather.icons[name].toSvg() instead.
Returns an SVG string.
Parameters
Name Type Description --------- ------ ----------- `name` string Icon `attrs` Object Key-value
Usage
` ` ` js feather .toSvg ( 'circle' ) // ' ' feather .toSvg ( 'circle' , { 'stroke-width' : 1 } ) // ' ' feather .toSvg ( 'circle' , { class : 'foo bar' } ) // ' ' ` ` `
Contributing
Related Projects
License