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 thebootstrap_iconsicon pack.A
bootstrap-icons: dependency inpackage.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 / pnpmThis 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:
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:
Install it:
npm install <icon-package>.Add a copy step to the build. The Bootstrap Icons sync lives in
plugins.mjsas thebootstrapIconsPlugin; copy that pattern for your own package, for example:Then add
myIconsPluginto thepluginsarray inbuild.mjs,build-dev.mjsandwatch.mjs(alongsidebootstrapIconsPlugin).Add a new pack to
<subtheme>.icons.ymlwith its ownsourcesglob andtemplate(match the icon set'sviewBoxand class conventions).Run
npm run devand thendrush cr.
Last updated