Icon

The QIcon component allows you to easily insert icons within other components or any other area of your pages. Quasar currently supports: Material Icons , Font Awesome, Ionicons, MDI, Eva Icons and Themify Icons.

Installing


// quasar.conf.js

return {
  framework: {
    // NOT needed if using auto-import feature:
    components: [
      'QIcon'
    ]
  }
}

Usage

WARNING

Make sure that you installed the icon library that you are using, otherwise it won’t show up!

Icons name cheatsheet

<q-icon name="..." />
NamePrefixExamplesNotes
material-iconsNonethumb_upNotice the underline character instead of dash or space
material-icons-outlinedo_o_thumb_upNotice the underline character instead of dash or space; Requires Quasar 1.0.5+
material-icons-roundr_r_thumb_upNotice the underline character instead of dash or space; Requires Quasar 1.0.5+
material-icons-sharps_s_thumb_upNotice the underline character instead of dash or space; Requires Quasar 1.0.5+
ionicons-v4ion-, ion-md-, ion-ios-, ion-logo-ion-heart, ion-logo-npm, ion-md-airplaneUse QIcon instead of <ion-icon> component; Logo icons require ‘ion-logo-’ prefix
fontawesome-v5fa[s,r,l,b] fa-“fas fa-ambulance”QIcon “name” property is same as “class” attribute value in Fontawesome docs examples (where they show <i> tags)
mdi-v4mdi-mdi-alert-circle-outlineNotice the use of dash characters; Use only one of mdi-v4 or mdi-v3
mdi-v3mdi-mdi-alert-circle-outlineNotice the use of dash characters; Use only one of mdi-v4 or mdi-v3
eva-iconseva-eva-shield-outline, eva-activity-outlineNotice the use of dash characters
themifyti-ti-hand-point-upNotice the use of dash characters

Size & colors

All icons are webfont icons. This means that you can change size by manipulating font-size CSS property. And also, they inherit the current CSS text color used.

Basic



For icon properties on different Quasar components you won’t have the means to specify an icon for each platform, but you can achieve the same effect with:

<q-btn
  :icon="$q.platform.is.ios ? 'settings' : 'ion-ios-gear-outline'"
/>
Standard sizes



Images instead of webfont

You can also make an icon point to an image URL instead of relying on any webfont, by using the img: prefix.

All icon related props of Quasar components can make use of this.

<q-icon name="img:https://cdn.quasar.dev/logo/svg/quasar-logo.svg" />
<q-btn icon="img:https://cdn.quasar.dev/logo/svg/quasar-logo.svg" ... />
<q-icon name="img:statics/my/path/to/some.svg" />

TIP

Remember that you can place images in your /src/statics folder too and point to them. You don’t always need a full URL.

This is not restricted to SVG only. You can use whatever image type you want (png, jpg, …):

<q-icon name="img:statics/bla/bla/my.png" />
<q-btn icon="img:statics/bla/bla/my.jpg" ... />
<q-input clearable clear-icon="img:statics/bla/bla/my.gif" ... />

It is also possible to inline the image (svg, png, jpeg, gif…) and dynamically change its style (svg):

<q-icon name="img:data:image/svg+xml;charset=utf8,<svg xmlns='http://www.w3.org/2000/svg' height='140' width='500'><ellipse cx='200' cy='80' rx='100' ry='50' style='fill:yellow;stroke:purple;stroke-width:2' /></svg>" />
Dynamic SVG



You can also base64 encode an image and supply it. The example below is with a QBtn, but the same principle is involved when dealing with any icon prop or with QIcon:

<q-btn icon="
img:data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" ... />

Custom mapping

v1.4.0+

Should you want, you can customize the mapping of icon names. This can be done by overriding $q.iconMapFn. The recommended place to do it is in the created() hook of your /src/App.vue component.

The syntax for $q.iconMapFn is as follows:

/* Syntax */
iconMapFn (String: iconName) => Object / void 0 (undefined)

/*
 The returned Object (if any) must be one of the following forms:

 1. Defines how to interpret icon
 {
   cls: String // class name(s)
   content: String // optional, in case you are using a ligature font
                   // and you need it as content of the QIcon
  }

  2. Acts essentially as a map to another icon
  {
    icon: String // the mapped icon String, which will be handled
                 // by Quasar as if the original QIcon name was this value
  }
*/

Let’s take both cases now.

1. Support for custom icon library

This is especially useful when you are using a custom icon library (that doesn’t come with Quasar and its @quasar/extras package).

created () {
  // Example of adding support for
  // <q-icon name="app:...." />
  // This includes support for all "icon" props
  // of Quasar components

  this.$q.iconMapFn = (iconName) => {
    // iconName is the content of QIcon "name" prop

    // your custom approach, the following
    // is just an example:
    if (iconName.startsWith('app:') === true) {
      // we strip the "app:" part
      const name = iconName.substring(4)

      return {
        cls: 'my-app-icon ' + name
      }
    }

    // when we don't return anything from our
    // iconMapFn, the default Quasar icon mapping
    // takes over
  }
}

Notice in the examples above that we are returning a my-app-icon class that gets applied to QIcon if our icon starts with app: prefix. We can use it to define how QIcon should react to it, from a CSS point of view.

Let’s assume we have our own webfont called “My App Icon”.

/*
  For this example, we are creating:
  /src/css/my-app-icon.css
*/

.my-app-icon {
  font-family: 'My App Icon';
  font-weight: 400;
}

@font-face {
  font-family: 'My App Icon';
  font-style: normal; /* whatever is required for your */
  font-weight: 400;   /* webfont.... */
  src: url("./my-app-icon.woff2") format("woff2"), url("./my-app-icon.woff") format("woff");
}

We should then edit our quasar.conf.js (if using Quasar CLI) to add the newly created CSS file into our app:

css: [
  // ....
  'my-app-icon.css'
]

And also add “my-app-icon.woff2” and “my-app-icon.woff” files into the same folder as “my-app-icon.css” (or somewhere else, but edit the relative paths (see “src:” above) to the woff/woff2 files).

2. Simply mapping a few icons

const myIcons = {
  'app:icon1': 'img:/path/to/icon1.svg',
  'app:icon2': 'img:/path/to/icon2.svg',
  'app:copy': 'fas fa-copy',
}

// ...
created () {
  this.$q.iconMapFn = (iconName) => {
    const icon = myIcons[iconName]
    if (icon !== void 0) {
      return { icon: icon }
    }
  }
}

Now we can use <q-icon name="app:copy" /> or <q-icon name="app:icon1" /> and QIcon will treat “app:copy” and “app:icon1” as if they were written as “fas fa-copy” and “img:/path/to/icon1.svg”.

QIcon API