### Install Icon Collections
Source: https://github.com/hyoban/tailwindcss-icons/blob/main/README.md
Install the necessary icon collections. You can install all icons from @iconify/json or individual packages like @iconify-json/mdi.
```sh
# install every icon:
npm i @iconify/json -D
# or install individual packages like this:
npm i @iconify-json/mdi @iconify-json/lucide -D
```
--------------------------------
### Install Tailwindcss Icons Plugin and Icon Packages
Source: https://context7.com/hyoban/tailwindcss-icons/llms.txt
Install the main plugin and icon collections as development dependencies. Consider installing individual icon packages for better performance.
```bash
# Install the plugin
npm i @egoist/tailwindcss-icons -D
# Install all icons (50MB)
npm i @iconify/json -D
# Or install individual icon packages (recommended)
npm i @iconify-json/mdi @iconify-json/lucide @iconify-json/heroicons -D
```
--------------------------------
### Install Tailwind CSS Icons Plugin
Source: https://github.com/hyoban/tailwindcss-icons/blob/main/README.md
Install the package as a development dependency using npm.
```sh
npm i @egoist/tailwindcss-icons -D
```
--------------------------------
### HTML Usage Examples
Source: https://context7.com/hyoban/tailwindcss-icons/llms.txt
Examples of using icons in HTML with various TailwindCSS utilities for styling and layout. Icons inherit text color and scale with text size.
```html
Welcome
```
--------------------------------
### Load Icon Collections with getIconCollections
Source: https://context7.com/hyoban/tailwindcss-icons/llms.txt
Helper function to load icon data from installed packages or `@iconify/json`. Pass the returned objects to `iconsPlugin`. Auto-discovery is available by omitting the `collections` argument.
```typescript
// tailwind.config.ts
import { getIconCollections, iconsPlugin } from '@egoist/tailwindcss-icons'
// Load specific collections (recommended for performance)
const collections = getIconCollections(['mdi', 'lucide', 'tabler'])
// Load all collections from @iconify/json (requires @iconify/json to be installed)
const allCollections = getIconCollections('all')
export default {
plugins: [
iconsPlugin({
collections: collections,
}),
],
}
// Auto-discovery mode: omit collections to auto-detect installed @iconify-json/* packages
export default {
plugins: [
iconsPlugin(), // Automatically discovers @iconify-json/heroicons, etc.
],
}
```
--------------------------------
### getIconCollections Usage
Source: https://context7.com/hyoban/tailwindcss-icons/llms.txt
Use the `getIconCollections` helper function to load icon data from installed `@iconify-json/*` packages or from `@iconify/json`.
```APIDOC
## getIconCollections
### Description
A helper function that loads icon data from installed `@iconify-json/*` packages or from `@iconify/json`. Returns icon collection objects that can be passed to the `iconsPlugin`.
### Method
`getIconCollections(collections: string[] | 'all')`
### Parameters
#### Path Parameters
- **collections** (string[] | 'all') - Required - An array of icon collection names (e.g., `['mdi', 'lucide']`) or the string 'all' to load all collections from `@iconify/json`.
### Request Example
```typescript
// tailwind.config.ts
import { getIconCollections, iconsPlugin } from '@egoist/tailwindcss-icons'
// Load specific collections (recommended for performance)
const collections = getIconCollections(['mdi', 'lucide', 'tabler'])
// Load all collections from @iconify/json (requires @iconify/json to be installed)
const allCollections = getIconCollections('all')
export default {
plugins: [
iconsPlugin({
collections: collections,
}),
],
}
// Auto-discovery mode: omit collections to auto-detect installed @iconify-json/* packages
export default {
plugins: [
iconsPlugin(), // Automatically discovers @iconify-json/heroicons, etc.
],
}
```
```
--------------------------------
### Generated CSS Output for Icon
Source: https://context7.com/hyoban/tailwindcss-icons/llms.txt
Example of the CSS output generated by the plugin for an icon class, showing how SVG is embedded as a data URI mask. This demonstrates how icons are rendered purely with CSS.
```css
/* Generated CSS for i-mdi-home */
.i-mdi-home {
display: inline-block;
width: 1em;
height: 1em;
background-color: currentColor;
-webkit-mask-image: var(--svg);
mask-image: var(--svg);
-webkit-mask-repeat: no-repeat;
mask-repeat: no-repeat;
-webkit-mask-size: 100% 100%;
mask-size: 100% 100%;
--svg: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='24' height='24'%3E%3Cpath fill='black' d='M10 20v-6h4v6h5v-8h3L12 3L2 12h3v8z'/%3E%3C/svg%3E");
}
/* With scale: 1.5 option */
.i-mdi-home {
width: 1.5em;
height: 1.5em;
/* ... other properties */
}
/* With extraProperties option */
.i-mdi-home {
vertical-align: middle;
/* ... other properties */
}
```
--------------------------------
### dynamicIconsPlugin Configuration
Source: https://context7.com/hyoban/tailwindcss-icons/llms.txt
Enable dynamic icon loading at build time using bracket notation with `dynamicIconsPlugin`.
```APIDOC
## dynamicIconsPlugin Configuration
### Description
A companion plugin that enables dynamic icon loading at build time using bracket notation. This is useful when you have `@iconify/json` installed and want to use any icon without pre-registering collections.
### Method
`dynamicIconsPlugin(options)`
### Parameters
#### Request Body
- **scale** (number) - Optional - The scale factor relative to font size (default: 1).
- **strokeWidth** (number) - Optional - Customizes stroke width for stroke-based icons.
### Request Example
```typescript
// tailwind.config.ts
import { dynamicIconsPlugin, iconsPlugin } from '@egoist/tailwindcss-icons'
import type { Config } from 'tailwindcss'
export default {
content: ['./src/**/*.{html,js,ts,jsx,tsx}'],
plugins: [
// Static plugin for autocomplete on frequently used icons
iconsPlugin(),
// Dynamic plugin for on-demand icon loading
dynamicIconsPlugin({
scale: 1,
strokeWidth: 2,
}),
],
} satisfies Config
```
### Dynamic Usage
```html
```
```
--------------------------------
### Configure Plugin with CSS
Source: https://context7.com/hyoban/tailwindcss-icons/llms.txt
Configure the plugin using the new TailwindCSS v4 CSS-based configuration syntax in `app.css`. This allows for basic usage or configuration with options like scale and prefix.
```css
/* app.css */
/* Basic usage */
@plugin '@egoist/tailwindcss-icons';
/* With options */
@plugin '@egoist/tailwindcss-icons' {
scale: 1.5;
prefix: icon;
}
```
--------------------------------
### Use Icons in HTML
Source: https://github.com/hyoban/tailwindcss-icons/blob/main/README.md
Apply icons as CSS classes using the 'i-' prefix followed by the collection and icon name.
```html
```
--------------------------------
### Configure dynamicIconsPlugin for On-Demand Icon Loading
Source: https://context7.com/hyoban/tailwindcss-icons/llms.txt
Enable dynamic icon loading at build time using bracket notation. Useful with `@iconify/json` for using any icon without pre-registering collections. Combine with `iconsPlugin` for autocomplete.
```typescript
// tailwind.config.ts
import { dynamicIconsPlugin, iconsPlugin } from '@egoist/tailwindcss-icons'
import type { Config } from 'tailwindcss'
export default {
content: ['./src/**/*.{html,js,ts,jsx,tsx}'],
plugins: [
// Static plugin for autocomplete on frequently used icons
iconsPlugin(),
// Dynamic plugin for on-demand icon loading
dynamicIconsPlugin({
scale: 1,
strokeWidth: 2,
}),
],
} satisfies Config
// Dynamic usage with bracket notation (collection--icon format):
//
//
//
// Can also use colon separator:
//
```
--------------------------------
### iconsPlugin Configuration
Source: https://context7.com/hyoban/tailwindcss-icons/llms.txt
Configure the iconsPlugin in your tailwind.config.ts to specify icon collections, customize class prefixes, scaling, stroke width, and add extra CSS properties.
```APIDOC
## iconsPlugin Configuration
### Description
Configure the `iconsPlugin` in your `tailwind.config.ts` to specify icon collections, customize class prefixes, scaling, stroke width, and add extra CSS properties.
### Method
`iconsPlugin(options)`
### Parameters
#### Request Body
- **collections** (Array