Icon

<wa-icon> Stable Since 2.0

Icons are scalable vector symbols that represent actions, content, or status throughout your application. They support Font Awesome and custom icon libraries with animation presets.

Web Awesome comes bundled with over 2,000 free icons courtesy of Font Awesome. These icons are part of the default icon library. Font Awesome Pro users can unlock additional icon families. Or, if you prefer, you can register your own custom icon library.

Not sure which icon to use? Find the perfect icon over at Font Awesome!

Examples

Link to This Section

Sizing

Link to This Section

Icons are sized relative to the current font size. To change their size, set the font-size property on the icon itself or on a parent element as shown below.

Colors

Link to This Section

Icons inherit their color from the current text color. Thus, you can set the color property on the <wa-icon> element or an ancestor to change the color.

Labels

Link to This Section

For non-decorative icons, use the label attribute to announce it to assistive devices.

Families & Variants

Link to This Section

The default icon library is Font Awesome Free, which comes with two icon families: classic and brands. Use the family attribute to set the icon family.

Many Font Awesome Pro icon families have variants such as thin, light, regular, and solid. Font Awesome Pro users can provide their kit code to unlock additional premium icon families, including sharp, duotone, sharp-duotone, and additional Pro+ icon packs.

For families that support multiple weights, use the variant attribute to set the variant.

Auto Width

Link to This Section

By default, icons have a 1em height and a fixed 1.25em width. Use the auto-width attribute to allow the icon to use its natural variable width.

Without auto-width

With auto-width

Rotating & Flipping

Link to This Section

Web Awesome supports Font Awesome's rotation and flip utilities for adjusting icon orientation. To rotate or flip icons, use the rotate and flip attributes when you reference an icon.

Animating

Link to This Section

Web Awesome supports Font Awesome's animation utilities for adding visual interest to icons. To select different types of animations, use the animation attribute when you reference an icon.

All icon animations respect prefers-reduced-motion and are automatically disabled when set to reduce.

Beat

Link to This Section

Use the beat animation to scale an icon up or down. This is useful for grabbing attention or for use with health/heart-centric icons.

Fade

Link to This Section

Use the fade animation to fade an icon in and out visually to grab attention in a subtle (or not so subtle) way.

Beat-Fade

Link to This Section

Use the beat-fade animation to grab attention by visually scaling and pulsing an icon in and out.

Bounce

Link to This Section

Use the bounce animation to grab attention by visually bouncing an icon up and down.

Flip

Link to This Section

Use the flip animation to rotate an icon in 3D space. By default, flip rotates an icon about the Y axis 180 degrees. Flipping is helpful for transitions, processing states, or for using physical objects that one flips in the real world.

Shake

Link to This Section

Use the shake animation to grab attention or note that something is not allowed by shaking an icon back and forth.

Spin

Link to This Section

Use the spin animation to get any icon to rotate, and use spin-pulse to have it rotate with eight steps. Use spin-reverse to rotate counter-clockwise. This works especially well with spinner and everything in the spinner icons category.

Duotone

Link to This Section

Font Awesome's Duotone icons change with the color property as well, but you can customize the primary and secondary colors independently using the --primary-color and --secondary-color custom properties. To change the opacity of either, use --primary-opacity and --secondary-opacity.

Note that these custom properties will not inherit and must be applied directly to the icon.

Duotone icons can be unlocked by providing a valid Font Awesome kit code.

Swap Duotone Opacity

Link to This Section

For duotone icons, you can swap the primary and secondary opacity values using the swap-opacity attribute. This is useful when you want to emphasize the secondary layer of the icon.

Normal duotone

Swapped duotone

Font Awesome Pro+ Icons

Link to This Section

If you're a Font Awesome Pro+ customer, you have access to even more icons! Just set the appropriate family, variant, and name on the icon.

Pro+ icons can be unlocked by providing a valid Font Awesome kit code.

Custom Icons

Link to This Section

Custom icons can be loaded individually with the src attribute. Only SVGs on a local or CORS-enabled endpoint are supported. If you're using more than one custom icon, it might make sense to register a custom icon library.

Self-hosting the Default Library

Link to This Section

By default, icons are loaded from the Font Awesome CDN. If you'd prefer to download the icons and serve them from your own server, you can use the setIconPath() function to point the default icon library at your self-hosted directory.

When you download Font Awesome, the archive will contain an svgs directory with subfolders such as solid/, regular/, brands/, etc. Copy the svgs directory (or its contents) into your project and set the icon path to point to it.

<script type="module">
  import { setIconPath } from '/dist/webawesome.js';

  // Point to the `svgs` directory from your Font Awesome download
  setIconPath('/assets/fontawesome/svgs');
</script>

After calling setIconPath(), icons will resolve to your self-hosted directory instead of the CDN. For example, <wa-icon name="house"> will load from /assets/fontawesome/svgs/solid/house.svg.

For more control over how icon URLs are constructed, you can use the getIconFolder() helper along with registerIconLibrary() to build a custom resolver. The getIconFolder() function maps a family and variant to the correct folder name, so you don't have to replicate that logic yourself.

<script type="module">
  import { getIconFolder, registerIconLibrary } from '/dist/webawesome.js';

  registerIconLibrary('default', {
    resolver: (name, family, variant) => {
      const folder = getIconFolder(name, family, variant);
      return `/assets/fontawesome/svgs/${folder}/${name}.svg?v=2`;
    },
  });
</script>

setIconPath() must be called before Web Awesome components are loaded, similar to setBasePath() and setKitCode().

Customizing the Default Library

Link to This Section

The default icon library contains over 2,000 icons courtesy of Font Awesome. These are the icons that display when you use <wa-icon> without the library attribute. If you prefer to have these icons resolve elsewhere or to a different icon library, register an icon library using the default name and a custom resolver.

For example, this will change the default icon library to use Bootstrap Icons loaded from the jsDelivr CDN.

<script type="module">
  import { registerIconLibrary } from '/dist/webawesome.js';

  registerIconLibrary('default', {
    resolver: (name, family) => {
      const suffix = family === 'filled' ? '-fill' : '';
      return `https://cdn.jsdelivr.net/npm/[email protected]/icons/${name}${suffix}.svg`;
    },
  });
</script>

Customize the default library to use SVG sprites

Link to This Section

To improve performance you can use a SVG sprites to avoid multiple trips for each SVG. The browser will load the sprite sheet once and then you reference the particular SVG within the sprite sheet using hash selector.

As always, make sure to benchmark these changes. When using HTTP/2, it may in fact be more bandwidth-friendly to use multiple small requests instead of 1 large sprite sheet.

When using sprite sheets, the wa-load and wa-error events will not fire.

For security reasons, browsers may apply the same-origin policy on <use> elements located in the <wa-icon> shadow DOM and may refuse to load a cross-origin URL. There is currently no defined way to set a cross-origin policy for <use> elements. For this reason, sprite sheets should only be used if you're self-hosting them.

<script type="module">
  import { registerIconLibrary } from '/dist/webawesome.js';

  registerIconLibrary('sprite', {
    resolver: name => `/assets/images/sprite.svg#${name}`,
    mutator: svg => svg.setAttribute('fill', 'currentColor'),
    spriteSheet: true,
  });
</script>

Customizing the System Library

Link to This Section

The system library contains only the icons used internally by Web Awesome components. Unlike the default icon library, the system library does not rely on physical assets. Instead, its icons are hard-coded as data URIs into the resolver to ensure their availability.

If you want to change the icons Web Awesome uses internally, you can register an icon library using the system name and a custom resolver. If you choose to do this, it's your responsibility to provide all of the icons that are required by components. You can reference src/components/library.system.ts for a complete list of system icons used by Web Awesome.

<script type="module">
  import { registerIconLibrary } from '/dist/webawesome.js';

  registerIconLibrary('system', {
    resolver: name => `/path/to/custom/icons/${name}.svg`,
  });
</script>

Third-party Icon Libraries

Link to This Section

You can register additional icons to use with the <wa-icon> component through icon libraries. Icon files can exist locally or on a CORS-enabled endpoint (e.g. a CDN). There is no limit to how many icon libraries you can register and there is no cost associated with registering them, as individual icons are only requested when they're used.

Web Awesome ships with two built-in icon libraries, default and system. The default icon library is provided courtesy of Font Awesome. The system icon library contains only a small subset of icons that are used internally by Web Awesome components.

To register an additional icon library, use the registerIconLibrary() function that's exported from dist/webawesome.js. At a minimum, you must provide a name and a resolver function. The resolver function translates an icon name to a URL where the corresponding SVG file exists. Refer to the examples below to better understand how it works.

If necessary, a mutator function can be used to mutate the SVG element before rendering. This is necessary for some libraries due to the many possible ways SVGs are crafted. For example, icons should ideally inherit the current text color via currentColor, so you may need to apply fill="currentColor or stroke="currentColor" to the SVG element using this function.

Here's an example that registers an icon library located in the /assets/icons directory.

<script type="module">
  import { registerIconLibrary } from '/dist/webawesome.js';

  registerIconLibrary('my-icons', {
    resolver: (name, family, variant) => `/assets/icons/${name}.svg`,
    mutator: svg => svg.setAttribute('fill', 'currentColor'),
  });
</script>

To display an icon, set the library and name attributes of an <wa-icon> element.

<!-- This will show the icon located at /assets/icons/smile.svg -->
<wa-icon library="my-icons" name="smile"></wa-icon>

If an icon is used before registration occurs, it will be empty initially but shown when registered.

The following examples demonstrate how to register a number of popular, open source icon libraries via CDN. Feel free to adapt the code as you see fit to use your own origin or naming conventions.

Bootstrap Icons

Link to This Section

This will register the Bootstrap Icons library using the jsDelivr CDN. This library has two families: regular and filled.

Icons in this library are licensed under the MIT License.


Boxicons

Link to This Section

This will register the Boxicons library using the jsDelivr CDN. This library has three variations: regular (bx-*), solid (bxs-*), and logos (bxl-*). A mutator function is required to set the SVG's fill to currentColor.

Icons in this library are licensed under the Creative Commons 4.0 License.



Lucide

Link to This Section

This will register the Lucide icon library using the jsDelivr CDN. This project is a community-maintained fork of the popular Feather icon library.

Icons in this library are licensed under the MIT License.

Heroicons

Link to This Section

This will register the Heroicons library using the jsDelivr CDN.

Icons in this library are licensed under the MIT License.

Iconoir

Link to This Section

This will register the Iconoir library using the jsDelivr CDN.

Icons in this library are licensed under the MIT License.

Ionicons

Link to This Section

This will register the Ionicons library using the jsDelivr CDN. This library has three variations: outline (default), filled (*-filled), and sharp (*-sharp). A mutator function is required to polyfill a handful of styles we're not including.

Icons in this library are licensed under the MIT License.



Jam Icons

Link to This Section

This will register the Jam Icons library using the jsDelivr CDN. This library has two variations: regular (default) and filled (*-f). A mutator function is required to set the SVG's fill to currentColor.

Icons in this library are licensed under the MIT License.


Material Icons

Link to This Section

This will register the Material Icons library using the jsDelivr CDN. This library has three variations: outline (default), round (*_round), and sharp (*_sharp). A mutator function is required to set the SVG's fill to currentColor.

Icons in this library are licensed under the Apache 2.0 License.



Remix Icon

Link to This Section

This will register the Remix Icon library using the jsDelivr CDN. This library groups icons by categories, so the name must include the category and icon separated by a slash, as well as the -line or -fill suffix as needed. A mutator function is required to set the SVG's fill to currentColor.

Icons in this library are licensed under the Apache 2.0 License.


Tabler Icons

Link to This Section

This will register the Tabler Icons library using the jsDelivr CDN. This library features over 1,950 open source icons.

Icons in this library are licensed under the MIT License.


Unicons

Link to This Section

This will register the Unicons library using the jsDelivr CDN. This library has two variations: line (default) and solid (*-s). A mutator function is required to set the SVG's fill to currentColor.

Icons in this library are licensed under the Apache 2.0 License. Some of the icons that appear on the Unicons website, particularly many of the solid variations, require a license and are therefore not available in the CDN.


Importing

Link to This Section

If you're using the autoloader or a hosted project, components load on demand — no manual import needed. To cherry-pick a component manually, use one of the following snippets.

CDN npm Self-Hosted React

Import this component directly from the CDN:

import 'https://ka-f.webawesome.com/[email protected]/components/icon/icon.js';

After installing Web Awesome via npm, import this component:

import '@awesome.me/webawesome/dist/components/icon/icon.js';

If you're self-hosting Web Awesome, import this component from your server:

import './webawesome/dist/components/icon/icon.js';

To import this component for React 18 or below, use the following code:

import WaIcon from '@awesome.me/webawesome/dist/react/icon/index.js';

Attributes & Properties

Link to This Section

Learn more about attributes and properties.

Events

Link to This Section

Learn more about events.

CSS custom properties

Link to This Section

Learn more about CSS custom properties.

CSS parts

Link to This Section

Learn more about CSS parts.

Need a hand? Report a bug Ask for help
    No results