Skip to content
Back to skills

Ux Icons

ASecurity

Symfony UX Icons: inline SVG icons, Lucide, Heroicons and other Iconify sets in Twig. Use for ux_icon(), twig:ux:icon, local SVGs, aliases, accessible icon labels, ux:icons:lock, auto_lock and offline deployment.

  • 191 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added May 26, 2026
developmentgophpbashdebugginggitapidatabasedocumentation

Works with

  • cli
  • api

Security analysis

A100/100

Pro scans all 4 files and shows the line behind each finding

Scanned December 2, 2026

npx -y skills add smnandre/symfony-ux-skills --skill ux-icons --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Ux Icons?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Ux Icons
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/smnandre-ux-icons/badge)](https://www.skillsdirectory.com/skills/smnandre-ux-icons)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: ux-icons
description: 'Symfony UX Icons: inline SVG icons, Lucide, Heroicons and other Iconify sets in Twig. Use for ux_icon(), twig:ux:icon, local SVGs, aliases, accessible icon labels, ux:icons:lock, auto_lock and offline deployment.'
license: MIT
metadata:
  author: Simon André
  url: https://smnandre.dev
---

# UX Icons

Render SVG icons from local files, custom sets or Iconify. Symfony embeds the SVG in the HTML, so the browser needs no separate icon request. When on-demand lookup is enabled, the server can fetch missing icons from Iconify.

## Installation

```bash
composer require symfony/ux-icons
```

## Quick Reference

```
ux_icon('name')                        Twig function
ux_icon('name', {class: 'w-4 h-4'})   with HTML attributes
<twig:ux:icon name="name" />           Twig component (requires ux-twig-component)
<twig:ux:icon name="set:name" />       icon from a specific set
```

## Rendering Icons

### Twig Function

```twig
{{ ux_icon('menu') }}
{# renders <svg ...>...</svg> #}

{{ ux_icon('user-profile', {class: 'w-4 h-4'}) }}
{# renders <svg class="w-4 h-4"> ... </svg> #}

{{ ux_icon('user-profile', {height: '16px', width: '16px'}) }}
{# renders <svg height="16px" width="16px" aria-hidden="true"> ... </svg> #}
```

### Twig Component (HTML Syntax)

Requires `symfony/ux-twig-component`.

```html
<twig:ux:icon name="user-profile" class="w-4 h-4" />

<twig:ux:icon name="flowbite:user-solid" />

<twig:ux:icon name="user-profile" height="16" width="16" />
```

Any HTML attribute added to the component or passed to the function is rendered on the `<svg>` element, with the same rules as other components: `null` and `false` omit the attribute, `true` renders `name=""`, and `aria-*` booleans render `"true"` / `"false"`.

## Icon Names

### Local Icons

Stored in `assets/icons/` by default. The file path (minus `.svg`) becomes the icon name:

```
assets/icons/
  ├─ close.svg           → ux_icon('close')
  ├─ menu.svg            → ux_icon('menu')
  └─ header/
     └─ logo.svg         → ux_icon('header:logo')
```

Subdirectories become prefixes separated by `:`. Use local icons for your own project-specific SVGs (app logo, custom illustrations).

### Iconify (On-Demand)

Use `prefix:name` syntax to pull icons from any Iconify set:

```twig
{# UI icons #}
{{ ux_icon('lucide:arrow-right') }}     {# Lucide #}
{{ ux_icon('tabler:heart') }}           {# Tabler #}
{{ ux_icon('heroicons:star-solid') }}   {# Heroicons #}
{{ ux_icon('mdi:check') }}              {# Material Design Icons #}

{# Country flags #}
<twig:ux:icon name="flagpack:fr" />
<twig:ux:icon name="flagpack:{{ country.code|lower }}" />

{# Brand logos #}
<twig:ux:icon name="simple-icons:symfony" />
<twig:ux:icon name="simple-icons:github" />

{# File type icons #}
<twig:ux:icon name="bi:filetype-pdf" />
<twig:ux:icon name="bi:filetype-{{ file.extension }}" />
```

On-demand lookup is enabled by default. If an icon is missing locally or from cache, the server can fetch it from Iconify during rendering. For an offline production deployment, [prepare local icons and disable the remote fallback](references/gotchas.md#production-deployment).

Browse all available sets at https://icon-sets.iconify.design/

## Configuration

```yaml
# config/packages/ux_icons.yaml
ux_icons:
    # Local directory for icon SVG files
    icon_dir: '%kernel.project_dir%/assets/icons'

    # Default HTML attributes added to every icon
    default_icon_attributes:
        fill: currentColor
        'font-size': '1.25em'

    # Aliases: shortcut name => full icon name
    aliases:
        dots: 'clarity:ellipsis-horizontal-line'
        'tabler:save': 'tabler:device-floppy'

    # Iconify integration
    iconify:
        enabled: true
        on_demand: true
        auto_lock: false      # since 3.4: save on-demand icons to icon_dir when rendered (dev only)
        endpoint: 'https://api.iconify.design'

    # Silently ignore missing icons (renders nothing instead of throwing)
    ignore_not_found: false
```

### Icon Sets

Define custom icon sets with their own prefix, source, and default attributes:

```yaml
ux_icons:
    icon_sets:
        # Local directory with custom attributes
        flags:
            path: '%kernel.project_dir%/assets/images/flags'
            icon_attributes:
                class: 'flag'
                fill: false           # "false" removes a default attribute

        # Alias an entire Iconify set under a shorter prefix
        icons:
            alias: 'lucide'           # ux_icon('icons:arrow-right') → lucide:arrow-right
```

### Aliases

Create shortcuts for frequently used icons:

```yaml
ux_icons:
    aliases:
        dots: 'clarity:ellipsis-horizontal-line'
        save: 'lucide:save'
        delete: 'lucide:trash-2'
        'tabler:save': 'tabler:device-floppy'   # can also remap within a set
```

```twig
{{ ux_icon('dots') }}    {# resolves to clarity:ellipsis-horizontal-line #}
{{ ux_icon('save') }}    {# resolves to lucide:save #}
```

## CLI Commands

### Import Icons Locally

Download icons from Iconify into your local `assets/icons/` directory:

```bash
# Import a single icon
php bin/console ux:icons:import flowbite:user-solid

# Import multiple icons
php bin/console ux:icons:import flowbite:user-solid flowbite:home-solid
```

### Lock All On-Demand Icons

Download all icons currently used via on-demand into local files (similar to a dependency lock):

```bash
php bin/console ux:icons:lock

# Force overwrite
php bin/console ux:icons:lock --force

# Verbose output (helps spot invalid icon names)
php bin/console ux:icons:lock -v
```

The scan only finds literal names in Twig templates. For names built dynamically (from a database, an enum...), either enable `auto_lock` in dev or register an icon finder.

### Auto-Lock in Development

```yaml
# config/packages/ux_icons.yaml
when@dev:
    ux_icons:
        iconify:
            auto_lock: true
```

Each on-demand icon is saved to `assets/icons/` the first time it renders. Commit those files: production renders them from local files.

### Custom Icon Finders

Since Symfony UX 3.5+, provide icon names from any source to `ux:icons:lock` and cache warming. Autoconfiguration registers the service (tag `ux_icons.finder` otherwise):

```php
use Symfony\UX\Icons\IconFinderInterface;

final class StatusIconFinder implements IconFinderInterface
{
    public function icons(): iterable
    {
        foreach (Status::cases() as $status) {
            yield $status->icon();
        }
    }
}
```

### Cache Warming

Since Symfony UX 3.6+, `cache:warmup` and `cache:clear` warm local icons. To also cache on-demand icons (HTTP requests to Iconify):

```bash
php bin/console ux:icons:warm-cache
```

## Accessibility

Icons get `aria-hidden="true"` automatically unless they have an `aria-label`, `aria-labelledby` or `title`. Decorative icons need nothing; give informative and functional icons a label:

```twig
{# Decorative: aria-hidden="true" is added for you #}
{{ ux_icon('lucide:star') }}

{# Informative or functional: announced by screen readers #}
{{ ux_icon('lucide:star', {'aria-label': 'Favorite'}) }}

{# Opt out of the automatic aria-hidden #}
<twig:ux:icon name="lucide:star" aria-hidden="false" />
```

## Key Principles

**Icons are inlined SVG.** The browser receives the SVG with the HTML. Icons can inherit `currentColor` and be styled with CSS.

**For offline production, ship local icons.** Run `ux:icons:lock` before deployment, account for dynamic names with an icon finder or explicit imports, then set `iconify.on_demand: false` in production.

**Rendered SVG is sanitized** (since Symfony UX 3.2+ and 2.36.1). Scripts, `<foreignObject>`, event handlers and unsafe `href` schemes are stripped from local and Iconify icons; `<style>` is kept.

**Attributes cascade.** Default attributes from config < icon set attributes < per-icon attributes. Use `false` to remove a default attribute for a specific set or icon.

**Prefer the HTML syntax.** `<twig:ux:icon name="..." />` reads better in templates and is consistent with other UX components.

## References

- [Symfony UX package and icon catalog](https://ux.symfony.com/icons) ([Markdown summary](https://ux.symfony.com/icons.md)) · [`symfony/ux-icons` on Packagist](https://packagist.org/packages/symfony/ux-icons).
- For icon sets, loading strategies and rendering, see the [Symfony UX Icons documentation](https://symfony.com/bundles/ux-icons).
- **API & Configuration** (all options, attributes, icon sets): [references/api.md](references/api.md)
- **Patterns** (common recipes, styling, dynamic icons): [references/patterns.md](references/patterns.md)
- **Gotchas** (common mistakes, debugging, caching): [references/gotchas.md](references/gotchas.md)

## See Also

- **twig-component**: `<twig:ux:icon>` inside component templates
- **ux-toolkit**: Shadcn UI and Flowbite recipes rely on `lucide:` and `flowbite:` icons

Files in this skill

  • SKILL.md7.3 KB
  • references/api.md4.5 KB
  • references/gotchas.md3.7 KB
  • references/patterns.md3.9 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.