Easy Way of Using Icons in Nuxt
Tags: webdev, beginners, tutorial, nuxt
Published: 2024-01-02 14:11:39


![Easy Way of Using Icons in Nuxt](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1rrkf8br5ihij11bjelb.jpg)

> Read [this post](https://webcraft-notes.com/blog/easy-way-of-using-icons-in-nuxt) in [my web notes](https://webcraft-notes.com/)!

Icons make websites look cool and help users navigate better. If you're into Nuxt.js and want to add icons without the confusion, you're in the right spot! This guide will show you the simple steps to bring icons into your Nuxt projects.

No matter if you're new to coding or a pro with Nuxt, this guide is for you. We'll take it step by step, making it super easy to follow along. Let's jazz up your projects together by learning the simple way to use icons in Nuxt.js. Ready to make your sites look awesome? Let's do this!

If you do not have a Nuxt project then open a terminal and use the following command to create a new one:  "npx nuxi@latest init <project-name>"

Install the dependencies: "npm install"

And now you are ready to start a project in development mode: "npm run dev"

We have a Nuxt starting page and an almost empty project. We can remove <NuxtWelcome /> tag from App.vue file and move to the next step.

If you have any issue with that please check Nuxt official documentation.

We will add some stiles and "div" container in the middle of the page so that it is easier to check our icons.

Now it's time to open a secret, we will use a "nuxt-icons" module. To install just execute a command: npm i nuxt-icons. Then add "nuxt-icons" to modules in nuxt.config.ts:
```
export default defineNuxtConfig({
  modules: ['nuxt-icons']
})
```
That's it, we can use "nuxt-icons" in our app. Usage:
- create "icons" folder in assets;
- save all your icons with ".svg" extension in the "icons" folder;
- use "<nuxt-icon>" tag with the "name" attribute, where the name is the name of your icon from the "icons" folder;
Here are some code examples:
```
<template>
  <div class="container">
    <div class="content">
      <div class="icon">
        <nuxt-icon name="car" filled />
      </div>
      <div class="icon">
        <nuxt-icon name="basketball" filled />
      </div>
      <div class="icon">
        <nuxt-icon name="beer" filled />
      </div>
      <div class="icon">
        <nuxt-icon name="house" filled />
      </div>
      <div class="icon">
        <nuxt-icon name="truck" filled />
      </div>
      <div class="icon">
        <nuxt-icon name="wand" filled />
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'IconsInNuxtApp',
}
</script>
```
We added six different icons with a "filled" attribute which allows us to use the original color from the SVG file. Here is the result:
![result](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/786qvtgcltjloytoovvl.png)
You can use any style for "nuxt-icons" as for typical "span" wrapped icon.
Incorporating icons into your Nuxt.js projects doesn't have to be complex. With the "nuxt-icons" module, you've unlocked an effortless way to elevate your website's visual appeal and user experience. By following these simple steps, you can seamlessly integrate icons, regardless of your coding expertise. Enhance your projects, captivate your audience, and add that extra touch of style effortlessly with icons in Nuxt.js.

> Also check my new articles in [my web notes](https://webcraft-notes.com/).