For the complete documentation index, see llms.txt. This page is also available as Markdown.

Icons (Icon API)

Integrate Bootstrap icons or any other icon set into your own theme with ease.

Drupal Icon API

Radix subthemes ship a Bootstrap Icons pack integrated with Drupal core's Icon API (stable in Drupal 11, available via the UI Icons backport on Drupal 10). This enables you to add SVG icons to templates and render arrays without requiring additional modules.

When you generate a subtheme from the Radix starterkit, the following are included automatically:

  • <subtheme>.icons.yml : declares the bootstrap_icons icon pack.

  • A bootstrap-icons : dependency in package.json.

  • A build step that copies the SVGs into assets/icons/bootstrap-icons. (feel free to disable that line if you don't need icons).

Setup

The icon SVGs are not committed to the subtheme. They are pulled from the bootstrap-icons npm package and copied into place by the build. After generating your subtheme, run an install and a build once:

npm install && npm run watch
# or: yarn && yarn dev / pnpm

This populates assets/icons/bootstrap-icons/ with the icon SVGs.

First-run note: the Icon API caches the list of discovered SVG files. If you enable your subtheme before the SVGs have been built, icons render blank. Run a cache rebuild once after the first build:

drush cr

Usage

In a Twig template

{{ icon('bootstrap_icons', 'house-fill', { size: 48 }) }}
{{ icon('bootstrap_icons', 'heart-fill', { size: 64, color: '#dc3545', alt: 'Favourite' }) }}

In a render array

Browse the available icon IDs at https://icons.getbootstrap.com.

Settings

The bootstrap_icons pack exposes three settings:

Setting
Type
Default
Description

size

integer

32

Width and height in pixels (8–256).

color

string

-

Any CSS color. Defaults to currentColor (inherits text color).

alt

string

-

Accessibility label. Leave empty for a decorative icon (renders aria-hidden).

The icon pack definition

The pack lives in <subtheme>.icons.yml:

Using a different icon set

To use another SVG icon library instead of (or alongside) Bootstrap Icons:

  1. Install it: npm install <icon-package>.

  2. Add a copy step to the build. The Bootstrap Icons sync lives in plugins.mjs as the bootstrapIconsPlugin; copy that pattern for your own package, for example:

    Then add myIconsPlugin to the plugins array in build.mjs, build-dev.mjs and watch.mjs (alongside bootstrapIconsPlugin).

  3. Add a new pack to <subtheme>.icons.yml with its own sources glob and template (match the icon set's viewBox and class conventions).

  4. Run npm run dev and then drush cr.

Last updated