Overview
Mermaid uses Iconify’s icon format and allows you to:- Register icon packs from the Iconify ecosystem
- Load icons from CDN or bundled packages
- Use custom names for icon packs (overriding the default prefix)
- Lazy load icon packs only when used in diagrams
Registering icon packs
Icon packs must be registered before they can be used in diagrams. TheregisterIconPacks() method accepts an array of icon pack configurations.
Using CDN
Load icon packs directly from a CDN:Using packages with lazy loading
Install an icon pack as a dependency and lazy load it:Lazy loading is recommended for better performance. Icons are only loaded when a diagram uses them.
Using packages without lazy loading
Load icon packs immediately when the application starts:Icon pack configuration
Each icon pack configuration supports the following properties:| Property | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Custom name for the icon pack (overrides the prefix) |
icons | object | Conditional | Icon data object (required if not using loader) |
loader | function | Conditional | Async function that returns icon data (required if not using icons) |
Custom names vs. default prefix
You can use a customname to simplify icon references:
- Custom name
- Default prefix
Using icons in diagrams
Once registered, icons can be used in diagrams using the syntaxpackName:iconName.
Flowchart example
Architecture diagram example
Available icon packs
Iconify provides access to over 150 icon sets. Popular options include:Brand icons
- @iconify-json/logos - Brand and technology logos
- @iconify-json/simple-icons - Simple icons for popular brands
- @iconify-json/devicon - Programming languages and development tools
General purpose
- @iconify-json/fa6-solid - Font Awesome 6 Solid
- @iconify-json/fa6-regular - Font Awesome 6 Regular
- @iconify-json/mdi - Material Design Icons
- @iconify-json/heroicons - Heroicons
Specialized
- @iconify-json/emojione - Emoji One
- @iconify-json/twemoji - Twitter Emoji
- @iconify-json/noto - Google Noto Emoji
Best practices
Performance optimization
- Use lazy loading - Load icon packs only when needed
- Register specific packs - Don’t register icon packs you won’t use
- Bundle icons in production - For better performance, bundle frequently used icons
Naming conventions
- Use short custom names - Make icon references easier to type
- Be consistent - Use the same naming pattern across your application
- Document your icons - Keep a list of registered icon packs
Error handling
Complete example
Here’s a complete example with multiple icon packs:Troubleshooting
Icons not displaying
- Check pack registration - Ensure the icon pack is registered before rendering diagrams
- Verify icon name - Check that the icon exists in the pack at icones.js.org
- Check syntax - Use
packName:iconNameformat - Inspect console - Look for loading errors in browser console
Performance issues
- Use lazy loading - Don’t load all icons upfront
- Minimize pack size - Only register packs you actually use
- Cache CDN responses - Configure proper cache headers
Next steps
Layouts
Configure layout engines for your diagrams
Math support
Add mathematical expressions to diagrams