# unplugin-icons
**Repository Path**: liuwave/unplugin-icons
## Basic Information
- **Project Name**: unplugin-icons
- **Description**: No description available
- **Primary Language**: Unknown
- **License**: MIT
- **Default Branch**: feat/add-css-support
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2025-06-12
- **Last Updated**: 2025-06-12
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# 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).
- ๐๏ธ **CSS** icons - Use icons as css stylesheets with or without any framework (experimental).
- ๐ฑ **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 beind 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 convension `~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](), 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({
// expiremental
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
```ts
// nuxt.config.js
export default {
buildModules: [
['unplugin-icons/nuxt', { /* options */ }],
],
}
```
> This module works for both Nuxt 2 and [Nuxt Vite](https://github.com/nuxt/vite)
Vue CLI
```ts
// vue.config.js
module.exports = {
configureWebpack: {
plugins: [
require('unplugin-icons/webpack')({ /* options */ }),
],
},
}
```
Svelte Kit
```ts
// svelte.config.js
import preprocess from 'svelte-preprocess'
import Icons from 'unplugin-icons/vite'
/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://github.com/sveltejs/svelte-preprocess
// for more information about preprocessors
preprocess: preprocess(),
kit: {
// hydrate the
element in src/app.html
target: '#svelte',
vite: {
plugins: [
Icons({
compiler: 'svelte',
}),
],
},
},
}
export default config
```
Svelte + Vite
Svelte support requires plugin dependency `@sveltejs/vite-plugin-svelte`:
```shell
npm i -D @sveltejs/vite-plugin-svelte
```
The `unplugin-icons` plugin should be configured on `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',
}),
],
})
```
###### Frameworks
Vue 3
Vue 3 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
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`:
```bash
npm i -D @svgr/core
```
```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`:
```bash
npm i -D @svgr/core
```
```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 Svelte Kit, on `src/global.d.ts` file:
```html
///
///
```
For Svelte + Vite, on `src/vite-env.d.ts` file:
```html
///
///
///
```
## Custom Icons
From v0.11, you can now load your own icons!
```ts
import { promises as fs } from '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
'my-yet-other-icons': FileSystemIconLoader('./assets/icons'),
}
})
```
Then use as
```ts
import IconAccount from '~icons/my-icons/account'
import IconFoo from '~icons/my-other-icons/foo'
import IconBar from '~icons/my-yet-other-icons/bar'
```
> ๐ก SVG Authoring Tips:
> - To make your icons color adaptable, set `fill="currentColor"` for `stroke="currentColor"` in your SVG.
> - Leave the `height` and `width` unspecified, we will set them for you.
### Use with Resolver
When using with resolvers for auto-importing, you will need to tell it your custom collection names:
```ts
IconResolver({
customCollections: [
'my-icons',
'my-other-icons',
'my-yet-other-icons',
]
})
```
See the [Vue 3 + Vite example](./examples/vite-vue3/vite.config.ts).
## Migrate from `vite-plugin-icons`
`package.json`
```diff
{
"devDependencies": {
- "vite-plugin-icons": "*",
+ "unplugin-icons": "^0.7.0",
}
}
```
`vite.config.json`
```diff
import Components from 'unplugin-components/vite'
- import Icons, { ViteIconsResolver } from 'vite-plugin-icons'
+ import Icons from 'unplugin-icons/vite'
+ import IconsResolver from 'unplugin-icons/resolver'
export default {
plugins: [
Vue(),
Components({
resolvers: IconsResolver(),
}),
Icons(),
],
}
```
`*` - imports usage
```diff
- import IconComponent from 'virtual:vite-icons/collection/name'
+ import IconComponent from '~icons/collection/name'
```
> You can still use `virtual:icons` prefix in Vite if you prefer, but it's not yet supported in Webpack, we are unifying it as a workaround in the docs.
## Options
You can set default styling for all icons.
The following config shows the default values of each option:
```ts
Icons({
scale: 1.2, // Scale of icons against 1em
defaultStyle: '', // Style apply to icons
defaultClass: '', // Class names apply to icons
compiler: null, // 'vue2', 'vue3', 'jsx'
jsx: 'react' // 'react' or 'preact'
})
```
## Auto Importing
Vue 2 & 3
Use with [`unplugin-vue-components`](https://github.com/antfu/unplugin-vue-components)
For example in Vite:
```js
// vite.config.js
import Vue from '@vitejs/plugin-vue'
import Icons from 'unplugin-icons/vite'
import IconsResolver from 'unplugin-icons/resolver'
import Components from 'unplugin-vue-components/vite'
export default {
plugins: [
Vue(),
Components({
resolvers: IconsResolver(),
}),
Icons(),
],
}
```
Then you can use any icons as you want without explicit importing. Only the used icons will be bundled.
```html
```
React & Solid
Use with [`unplugin-auto-import`](https://github.com/antfu/unplugin-auto-import)
For example in Vite:
```js
// vite.config.js
import Icons from 'unplugin-icons/vite'
import IconsResolver from 'unplugin-icons/resolver'
import AutoImport from 'unplugin-auto-import/vite'
export default {
plugins: [
/* ... */
AutoImport({
resolvers: [
IconsResolver({
prefix: 'Icon',
extension: 'jsx'
})
],
}),
Icons({
compiler: 'jsx' // or 'solid'
}),
],
}
```
Then you can use any icons with the prefix `Icon` as you want without explicit importing. Type declarations will be generated on the fly.
```js
export function Component() {
return (
)
}
```
### Name Conversion
When using component resolver, you have to follow the name conversion for icons to be properly inferred.
```
{prefix}-{collection}-{icon}
```
The `collection` field follows [Iconify's collection IDs](https://iconify.design/icon-sets/).
By default, the prefix is set to `i` while you can customize via config
```ts
IconsResolver({
prefix: 'icon' // <--
})
```
```html
```
Non-prefix mode is also supported
```ts
IconsResolver({
prefix: false, // <--
// this is optional, default enabling all the collections supported by Iconify
enabledCollections: ['mdi']
})
```
```vue
```
### CSS Icons
You can use svg icons as a `css stylesheet` (no framework required):
```ts
import '~icons/{collection}/{icon}.css'
```
then add an `html` element with a `class` with a name following the convention: `{collection}-{icon}`.
For example:
```html
```
### Collection Aliases
When using component resolver, you have to use the name of the collection that can be long or redundant: for example,
when using `icon-park` collection you need to use it like this ``.
You can add an alias for any collection to the `IconResolver` plugin:
```ts
IconsResolver({
alias: {
park: 'icon-park',
fas: 'fa-solid',
...
}
})
```
You can use the alias or the collection name, the plugin will resolve both.
Following with the example and configuring the plugin with previous `alias` entry, you can now use
`` or ``.
## Sponsors
This project is part of my Sponsor Program
## License
MIT License ยฉ 2020-PRESENT [Anthony Fu](https://github.com/antfu)