Skip to content

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 ''
import { faTree } from ''
import { faDog } from ''
<FontAwesomeIcon :icon="faHouse" />
<FontAwesomeIcon :icon="faTree" />
<FontAwesomeIcon :icon="faDog" />

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.

// in main.ts
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']" />

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:

Set up the library

You’ll first create a library of all the icons you want to use in your project in the src/main.js or src/main.ts file. Here’s an example that adds the Solid style User Secret icon to the library:

/* Set up using Vue 3 */
import { createApp } from 'vue'
import App from './App.vue'
/* 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 { faUserSecret } from '@fortawesome/free-solid-svg-icons'
/* add icons to the library */
.component('font-awesome-icon', FontAwesomeIcon)

Calling the icons

You can now call the icons. You can add icons to your Vue 3 or Vue 2 project using a string format or an array format. Just use the syntax below wherever you want the icons to appear in your project, like in the src/App.vue file. Here’s the rest of the example we started above that adds the fa-user-secret icon into the app UI:

<div id="app">
<!-- Add the style and icon you want using the String format -->
<font-awesome-icon icon="fa-solid fa-user-secret" />
export default {
name: 'App'

Several icon in different styles

Here’s an example with a number of icons in different styles, just to give you a sense of how the syntax changes from style to style in your main.js file.

/* Vue 3 and Vue 2 use the same icon importing syntax */
/* add fontawesome core */
import { library } from '@fortawesome/fontawesome-svg-core'
/* add some free styles */
import { faTwitter } from '@fortawesome/free-brands-svg-icons'
import { faUserSecret } from '@fortawesome/free-solid-svg-icons'
/* add some pro styles */
import { faBicycle } from '@fortawesome/pro-regular-svg-icons'
import { faEnvelope } from '@fortawesome/pro-light-svg-icons'
import { faFeather } from '@fortawesome/pro-thin-svg-icons'
import { faHorseSaddle } from '@fortawesome/pro-duotone-svg-icons'
import { faAlien } from '@fortawesome/sharp-solid-svg-icons'
import { faPlateUtensils } from '@fortawesome/sharp-regular-svg-icons'
import { faFire } from '@fortawesome/sharp-light-svg-icons'
import { faDog } from '@fortawesome/sharp-thin-svg-icons'
/* add each imported icon to the library */
library.add(faTwitter, faUserSceret, faBicycle, faCoffee, faFeather, faHorseSaddle, faAlien, faFire, faDog)

When you want to reference those icons in your project, you can choose between a String or Array syntax.

<!-- Add Icons using String format -->
<font-awesome-icon icon="fa-brands fa-twitter" />
<font-awesome-icon icon="fa-solid fa-user-secret" />
<font-awesome-icon icon="fa-regular fa-bicycle" />
<font-awesome-icon icon="fa-light fa-envelope" />
<font-awesome-icon icon="fa-thin fa-feather" />
<font-awesome-icon icon="fa-duotone fa-horse-saddle" />
<font-awesome-icon icon="fa-sharp fa-solid fa-alien" />
<font-awesome-icon icon="fa-sharp fa-regular fa-plate-utensils" />
<font-awesome-icon icon="fa-sharp fa-light fa-fire" />
<font-awesome-icon icon="fa-sharp fa-thin fa-dog" />

Same icons, Different Styles

Using ES modules and import statements we can define unique names for two or more different styles of the same icon. Here’s is what your main.js file would look like:

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>

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.