# unplugin-icons
[](https://www.npmjs.com/package/unplugin-icons)
Access thousands of icons as components **on-demand** universally.
### Features
- ๐ Universal
- ๐คน **Any** icon sets - 100+ popular sets with over 10,000 icons, logos, emojis, etc. Powered by [Iconify](https://github.com/iconify/iconify).
- ๐ฆ **Major** build tools - Vite, Webpack, Rollup, Nuxt, etc. Powered by [unplugin](https://github.com/unjs/unplugin).
- ๐ช **Major** frameworks - Vanilla, Web Components, React, Vue 3, Vue 2, Solid, Svelte, and more. [Contribute](./src/core/compiles).
- ๐ฑ **Any** combinations of them!
- โ๏ธ On-demand - Only bundle the icons you really use, while having all the options.
- ๐จ SSR / SSG friendly - Ship the icons with your page, no more FOUC.
- ๐ Stylable - Change size, color, or even add animations as you would with styles and classes.
- ๐ฅ [Custom icons](#custom-icons) - load your custom icons to get universal integrations at ease.
- ๐ฒ [Auto Importing](#auto-importing) - Use icons as components directly in your template.
- ๐ฆพ TypeScript support.
- ๐ [Browse Icons](https://icones.js.org/)
๐ก **Story behind this tool**: [Journey with Icons Continues](https://antfu.me/posts/journey-with-icons-continues) - a blog post by Anthony
> **`vite-plugin-icons` has been renamed to `unplugin-icons`**, see the [migration guide](#migrate-from-vite-plugin-icons)
## Usage
Import icons names with the convention `~icons/{collection}/{icon}` and use them directly as components. [Auto importing is also possible](#auto-importing).
###### React
```jsx
import IconAccessibility from '~icons/carbon/accessibility'
import IconAccountBox from '~icons/mdi/account-box'
function App() {
return (
)
}
```
###### Vue
```html
```
## Install
### Plugin
```bash
npm i -D unplugin-icons
```
### Icons Data
We use [Iconify](https://iconify.design/) as the icons data source (supports 100+ iconsets).
You have two ways to install them:
###### Install Full Collection
```bash
npm i -D @iconify/json
```
`@iconify/json` (~120MB) includes all the iconsets from Iconify so you can install once and use any of them as you want (only the icons you actually use will be bundle into the production build).
###### Install by Icon Set
If you only want to use a few of the icon sets and don't want to download the entire collection, you can also install them individually with `@iconify-json/[collection-id]`.
For example, to install [Material Design Icons](https://icon-sets.iconify.design/mdi/), you can do:
```bash
npm i -D @iconify-json/mdi
```
To boost your workflow, it's also possible to let `unplugin-icons` handle that installation by enabling the `autoInstall` option.
```ts
Icons({
// experimental
autoInstall: true,
})
```
It will install the icon set when you import them. The right package manager will be auto-detected (`npm`, `yarn` or `pnpm`).
## Configuration
###### Build Tools
Vite
```ts
// vite.config.ts
import Icons from 'unplugin-icons/vite'
export default defineConfig({
plugins: [
Icons({ /* options */ }),
],
})
```
Rollup
```ts
// rollup.config.js
import Icons from 'unplugin-icons/rollup'
export default {
plugins: [
Icons({ /* options */ }),
],
}
```
Webpack
```ts
// webpack.config.js
module.exports = {
/* ... */
plugins: [
require('unplugin-icons/webpack')({ /* options */ }),
],
}
```
Nuxt
Nuxt 2 and [Nuxt Bridge](https://github.com/nuxt/bridge)
```ts
// nuxt.config.js
export default {
buildModules: [
['unplugin-icons/nuxt', { /* options */ }],
],
}
```
Nuxt 3
```ts
// nuxt.config.js
export default defineNuxtConfig({
modules: [
['unplugin-icons/nuxt', { /* options */ }]
],
})
```
Vue CLI
```ts
// vue.config.js
module.exports = {
configureWebpack: {
plugins: [
require('unplugin-icons/webpack')({ /* options */ }),
],
},
}
```
SvelteKit
The `unplugin-icons` plugin should be configured in the `vite.config.js` configuration file:
```ts
// vite.config.js
import { defineConfig } from 'vite'
import { sveltekit } from '@sveltejs/kit/vite'
import Icons from 'unplugin-icons/vite'
export default defineConfig({
plugins: [
sveltekit(),
Icons({
compiler: 'svelte',
})
]
})
```
Check instructions in the `Frameworks -> Svelte` section below if you faced module import errors.
Svelte + Vite
Svelte support requires the `@sveltejs/vite-plugin-svelte` plugin:
```shell
npm i -D @sveltejs/vite-plugin-svelte
```
The `unplugin-icons` plugin should be configured in the `vite.config.js` configuration file:
```ts
// vite.config.js
import { defineConfig } from 'vite'
import { svelte } from '@sveltejs/vite-plugin-svelte'
import Icons from 'unplugin-icons/vite'
export default defineConfig({
plugins: [
svelte(),
Icons({
compiler: 'svelte',
}),
],
})
```
Check instructions in the `Frameworks -> Svelte` section below if you faced module import errors.
Next.js
The `unplugin-icons` plugin should be configured on `next.config.js` configuration file:
```js
/** @type {import('next').NextConfig} */
module.exports = {
reactStrictMode: true,
webpack(config) {
config.plugins.push(
require('unplugin-icons/webpack')({
compiler: 'jsx',
jsx: 'react',
}),
)
return config
},
}
```
Check instructions in the `Frameworks -> React` section below if you faced module import errors.
โ ๏ธ **Warning:** to import an icon is necessary to explicitly add the `.jsx` extension to the import path, so that Next.js knows how to load it, by example:
```ts
import IconArrowRight from '~icons/dashicons/arrow-right.jsx';
// ^-- write `.jsx` to avoid
// https://github.com/antfu/unplugin-icons/issues/103
// ...some code later
```
See inside of `examples/next` for a working example project.
esbuild
```ts
// esbuild.config.js
import { build } from 'esbuild'
build({
/* ... */
plugins: [
require('unplugin-icons/esbuild')({
/* options */
}),
],
})
```
Astro
```ts
// astro.config.mjs
import { defineConfig } from 'astro/config'
import Icons from 'unplugin-icons/vite'
// https://astro.build/config
export default defineConfig({
vite: {
plugins: [
Icons({
compiler: 'astro',
}),
],
},
})
```
###### Frameworks
Vue 3 / Vue 2.7+
Vue 3 / Vue 2.7+ support requires peer dependency `@vue/compiler-sfc`:
```bash
npm i -D @vue/compiler-sfc
```
```ts
Icons({ compiler: 'vue3' })
```
Type Declarations
```jsonc
// tsconfig.json
{
"compilerOptions": {
"types": [
"unplugin-icons/types/vue",
]
}
}
```
Vue 2 (only for versions < 2.7)
Vue 2 support requires peer dependency `vue-template-compiler`:
```bash
npm i -D vue-template-compiler
```
```ts
Icons({ compiler: 'vue2' })
```
Type Declarations
```jsonc
// tsconfig.json
{
"compilerOptions": {
"types": [
"unplugin-icons/types/vue",
]
}
}
```
React
JSX support requires peer dependency `@svgr/core` and its plugin `@svgr/plugin-jsx`:
```bash
npm i -D @svgr/core @svgr/plugin-jsx
```
```ts
Icons({ compiler: 'jsx', jsx: 'react' })
```
Type Declarations
```jsonc
// tsconfig.json
{
"compilerOptions": {
"types": [
"unplugin-icons/types/react",
]
}
}
```
Preact
JSX support requires peer dependency `@svgr/core` and its plugin `@svgr/plugin-jsx`:
```bash
npm i -D @svgr/core @svgr/plugin-jsx
```
```ts
Icons({ compiler: 'jsx', jsx: 'preact' })
```
Type Declarations
```jsonc
// tsconfig.json
{
"compilerOptions": {
"types": [
"unplugin-icons/types/preact",
]
}
}
```
Solid
```ts
Icons({ compiler: 'solid' })
```
Type Declarations
```jsonc
// tsconfig.json
{
"compilerOptions": {
"types": [
"unplugin-icons/types/solid",
]
}
}
```
Svelte
```ts
Icons({ compiler: 'svelte' })
```
Type Declarations
For SvelteKit, in the `src/app.d.ts` file:
```ts
import 'unplugin-icons/types/svelte'
```
For Svelte + Vite, in the `src/vite-env.d.ts` file:
```js
///
///
///
```
Astro
Type Declarations
```jsonc
// tsconfig.json
{
"compilerOptions": {
"types": [
"unplugin-icons/types/astro",
]
}
}
```
Qwik
Qwik support requires peer dependency `@svgx/core`:
```bash
npm i -D @svgx/core
```
```ts
Icons({ compiler: 'qwik' })
```
Type Declarations
```jsonc
// tsconfig.json
{
"compilerOptions": {
"types": [
"unplugin-icons/types/qwik",
]
}
}
```
## Use RAW compiler from query params
From `v0.13.2` you can also use `raw` compiler to access the `svg` icon and use it on your html templates, just add `raw` to the icon query param.
For example, using `vue3`:
```vue
import RawMdiAlarmOff from '~icons/mdi/alarm-off?raw&width=4em&height=4em'
{{ RawMdiAlarmOff }}
import RawMdiAlarmOff2 from '~icons/mdi/alarm-off?raw&width=1em&height=1em'
{{ RawMdiAlarmOff2 }}
```
## Custom Icons
From `v0.11`, you can now load your own icons!
From `v0.13` you can also provide a transform callback to `FileSystemIconLoader`.
```ts
import { promises as fs } from 'node:fs'
// loader helpers
import { FileSystemIconLoader } from 'unplugin-icons/loaders'
Icons({
customCollections: {
// key as the collection name
'my-icons': {
account: '',
// load your custom icon lazily
settings: () => fs.readFile('./path/to/my-icon.svg', 'utf-8'),
/* ... */
},
'my-other-icons': async (iconName) => {
// your custom loader here. Do whatever you want.
// for example, fetch from a remote server:
return await fetch(`https://example.com/icons/${iconName}.svg`).then(res => res.text())
},
// a helper to load icons from the file system
// files under `./assets/icons` with `.svg` extension will be loaded as it's file name
// you can also provide a transform callback to change each icon (optional)
'my-yet-other-icons': FileSystemIconLoader(
'./assets/icons',
svg => svg.replace(/^