Skip to content
Say hello to Web Awesome, the biggest and best library of open-source web components.
Pre-order today!

Add Icons with Vue

When adding icon in a project configured with vue-cli, you’ll first create a library of icons, and then you can call them anywhere in your UI.

Using a Kit Package

If you’ve created a Kit and installed it in your project, you’re ready to get going.

By prefix and name

<script setup lang="ts">
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
import { byPrefixAndName } from ''
<FontAwesomeIcon :icon="byPrefixAndName.fas['house']" />

For this to work, you’ll need to have a Kit that contains the icons in the examples. If you’re not familiar with how Kits work, you can find out here.

Importing specific icons

An alternative to using the prefix and name is by importing icons directly. This is your best bet at leveraging tree-shaking if that’s useful to you.

<script setup lang="ts">
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
import { faHouse } from ''
<FontAwesomeIcon :icon="faHouse" />

You can use all the icons in a family and style, too. But this will put the kibosh on tree-shaking (Probably‽, are we using A.I. for this yet?).

<script setup lang="ts">
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
import { fas, far, fal } from ''
<FontAwesomeIcon :icon="fas.faHouse" />
<FontAwesomeIcon :icon="far.faMouse" />
<FontAwesomeIcon :icon="fal.faCheese" />

Using the library

Another mechanism that the SVG Core provides is a JavaScript class called Library.

With a subsetted Kit, this can be an easy way to add all icons once and use them with a syntax that requires less typing.

import './assets/main.css'
import { createApp } from 'vue'
import { createPinia } from 'pinia'
import App from './App.vue'
import router from './router'
/* import the fontawesome core */
import { library } from '@fortawesome/fontawesome-svg-core'
/* import font awesome icon component */
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
/* import specific icons */
import { all } from ''
/* add icons to the library */
const app = createApp(App)
app.component('font-awesome-icon', FontAwesomeIcon)

Now all icons in the Kit have been added in just one, easy line. No fuss, no muss.

Using it doesn’t require importing the icons. You just need an array or string.

Also note here that we’ve switched from importing and using FontAwesomeIcon directly and are using the already registered component, through app.component(). That means our syntax shifts slightly and we use <font-awesome-icon ...> now.

<font-awesome-icon :icon="['fas', 'house']" />

Custom icons are just as easy.

<font-awesome-icon :icon="['fak', 'my-icon']" />

Add Some Style

Now that you have some icons on the page, add some pieces of flair! Check out all the styling options you can use with Font Awesome and Vue.

Importing from SVG Icon Packages

If you can’t or don’t want to use a Kit, you can explicitly add individual icons to each component. Here’s a simple example:

Add Individual Icons Explicitly

<script setup lang="ts">
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
import { faEnvelope } from '@fortawesome/free-solid-svg-icons'
<FontAwesomeIcon icon={faEnvelope} />

Notice that the faEnvelope icon is imported from @fortawesome/free-solid-svg-icons as an object and then provided to the icon prop as an object.

Add Icons Globally

We like to travel light so we don’t recommend this method unless you know what you’re doing. Globally importing icons can increase the size of your bundle with icons you aren’t using. It also couples your components to another module that manages your icons.

First, you’ll import the icons you want to use via a “library” in the initializing module of your Vue application, like App.js. Here’s an example of that:

<script setup lang="ts">
import { library } from '@fortawesome/fontawesome-svg-core'
import { fas } from '@fortawesome/free-solid-svg-icons'
import { faTwitter, faFontAwesome } from '@fortawesome/free-brands-svg-icons'
import { faHatCowboy } from '@fortawesome/pro-thin-svg-icons'
import { faHatChef } from '@fortawesome/sharp-solid-svg-icons'
import { faPlateUtensils } from '@fortawesome/sharp-regular-svg-icons'
library.add(fas, faTwitter, faFontAwesome, faHatCowboy, faHatChef, faPlateUtensils)

In our call to library.add() we’re passing:

  • fas: which represents all of the icons in @fortawesome/free-solid-svg-icons. (Be careful importing whole styles - it can be a LOT of icons!) So any of the icons in that package may be referenced by icon name as a string anywhere else in our app. For example: coffee, check-square, or spinner.
  • faTwitter, faFontAwesome, faHatCowboy, faHatChef, and faPlateUtensils: Adding each of these icons individually allows us to refer to them throughout our app by their icon string names, twitter, font-awesome, hat-cowboy, hat-chef, and plate-utensils.

You can then use any of those icons anywhere in your app without needing to re-import into each component. So if you used icons in a couple of components, that would end up looking something like this:

<script setup lang="ts">
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
<FontAwesomeIcon icon="fa-solid fa-check-square" />
<FontAwesomeIcon icon="fa-regular fa-coffee" />
<script setup lang="ts">
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
<FontAwesomeIcon icon="fa-brands fa-twitter" />
<FontAwesomeIcon icon="fa-brands fa-font-awesome" />

You’ll notice we were able use the imported brand icons without explicitly importing them in the component. And we used the square-check, and envelope icons without explicitly importing them anywhere. But, our bundle now has over 1000 solid icons plus the two brand icons we added, which is more than we’re using - a good reason to avoid importing a whole style.

Same icons, Different Styles

Using ES modules and import statements we can define unique names for two different styles of the same icon. Here’s an example:

import { library } from '@fortawesome/fontawesome-svg-core'
import { faCoffee as fasFaCoffee } from '@fortawesome/pro-solid-svg-icons'
import { faCoffee as farFaCoffee } from '@fortawesome/pro-regular-svg-icons'
import { faCoffee as falFaCoffee } from '@fortawesome/pro-light-svg-icons'
import { faCoffee as fatFaCoffee } from '@fortawesome/pro-thin-svg-icons'
import { faCoffee as fadFaCoffee } from '@fortawesome/pro-duotone-svg-icons'
import { faCoffee as fassFaCoffee } from '@fortawesome/sharp-solid-svg-icons'
import { faCoffee as fasrFaCoffee } from '@fortawesome/sharp-regular-svg-icons'
import { faCoffee as faslFaCoffee } from '@fortawesome/sharp-light-svg-icons'
import { faCoffee as fastFaCoffee } from '@fortawesome/sharp-thin-svg-icons'
library.add(fasFaCoffee, farFaCoffee, falFaCoffee, fatFaCoffee, fadFaCoffee, fassFaCoffee, fasrFaCoffee, faslFaCoffee, fastFaCoffee)

Add the icons to your component.

<font-awesome-icon icon="fa-solid fa-coffee" />
<font-awesome-icon icon="fa-regular fa-coffee" />
<font-awesome-icon icon="fa-light fa-coffee" />
<font-awesome-icon icon="fa-thin fa-coffee" />
<font-awesome-icon icon="fa-duotone fa-coffee" />
<font-awesome-icon icon="fa-sharp fa-solid fa-coffee" />
<font-awesome-icon icon="fa-sharp fa-regular fa-coffee" />
<font-awesome-icon icon="fa-sharp fa-light fa-coffee" />
<font-awesome-icon icon="fa-sharp fa-thin fa-coffee" />

Watch out for self-closing tags in HTML

If you are using inline templates or HTML as templates you need to be careful to avoid self-closing tags. Read more about self-closing tags on Vue.js. If you are writing these types of templates, you’ll need to adjust the syntax to be valid HTML, like this:

<!-- Add Icons using String format -->
<font-awesome-icon icon="fa-regular fa-envelope"></font-awesome-icon>