Don't Miss Out! To celebrate the release of Font Awesome Sharp, get $20 off a new Pro subscription for a limited time!

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

Advertisement

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 file. Here's an example that adds the Solid style User Secret icon to the library:

    /* Set up using Vue 2 */
    import Vue from 'vue'
    import App from './App'
    
    /* 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 */
    library.add(faUserSecret)
    
    /* add font awesome icon component */
    Vue.component('font-awesome-icon', FontAwesomeIcon)
    
    Vue.config.productionTip = false
    
    /* eslint-disable no-new */
    new Vue({
      el: '#app',
      components: { App },
      template: '<App/>'
    })
    
    /* 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 */
    library.add(faUserSecret)
    
    createApp(App)
    .component('font-awesome-icon', FontAwesomeIcon)
    .mount('#app')
    

    Call the Icons

    Using Vue 2 or Vue 3 ?

    You can add icons to your Vue 2 or Vue 3 project using a string format or an array format.

    You can now call the icons, 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:

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

      Watch your camels and kebabs, Bob!

      Note that you add the icons in camelCase in main.js but in kebab-case in App.vue.

      Several icons 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.

      Font Awesome Sharp requires v6.2.0!

      Make sure you have an active Pro-level plan or a Pro license with access to Font Awesome v6.2.0 or greater in order to use our Sharp Solid icons.
      /* Vue 2 and Vue 3 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'
      
      /* add each imported icon to the library */
      library.add(faTwitter, faUserSceret, faBicycle, faCoffee, faFeather, faHorseSaddle, faAlien)
      

      Time to add those icons.

        <!-- 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" />
        
        <!-- Add Icons using Array format -->
        <font-awesome-icon :icon="['fab', 'twitter']" />
        <font-awesome-icon :icon="['fas', 'user-secret']" />
        <font-awesome-icon :icon="['far', 'bicycle']" />
        <font-awesome-icon :icon="['fal', 'envelope']" />
        <font-awesome-icon :icon="['fat', 'feather']" />
        <font-awesome-icon :icon="['fad', 'horse-saddle']" />
        <font-awesome-icon :icon="['fass', 'alien']" />
        
        Advertisement

        Same icon, different styles

        You can also import the same icon from different styles with some help from ES import. Import in the main.js file:

        /* Vue 2 and Vue 3 use the same icon importing syntax */
        import { library } from '@fortawesome/fontawesome-svg-core'
        import { faCoffee as fasCoffee } from '@fortawesome/pro-solid-svg-icons'
        import { faCoffee as farCoffee } from '@fortawesome/pro-regular-svg-icons'
        import { faCoffee as falCoffee } from '@fortawesome/pro-light-svg-icons'
        import { faCoffee as fadCoffee } from '@fortawesome/pro-duotone-svg-icons'
        import { faCoffee as fassCoffee } from '@fortawesome/sharp-solid-svg-icons'
        
        library.add(fasCoffee, farCoffee, falCoffee, fadCoffee, fassCoffee)
        

        Add the icons to your component.

          <!-- Add Icons using String format -->
          <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-duotone fa-coffee" />
          <font-awesome-icon icon="fa-sharp fa-solid fa-coffee" />
          
          <!-- Add Icons using Array format -->
          <font-awesome-icon :icon="['fas', 'coffee']" />
          <font-awesome-icon :icon="['far', 'coffee']" />
          <font-awesome-icon :icon="['fal', 'coffee']" />
          <font-awesome-icon :icon="['fat', 'coffee']" />
          <font-awesome-icon :icon="['fad', 'coffee']" />
          <font-awesome-icon :icon="['fass', '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 (opens new window). 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 Icons using Array format -->
            <font-awesome-icon :icon="['far', 'envelope']"></font-awesome-icon>
            

            Looking to use computed or component properties?

            We've got those too. Get the low-down on how to add icons as computed or component properties.

            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 React.

            Express Yourself with Some Styling!