본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

quasar-vue-components-icon

원문 보기 위키 갱신

QIcon 컴포넌트를 쓰면 다른 컴포넌트 안이나 페이지의 어느 영역에든 아이콘을 쉽게 넣을 수 있어요.

Quasar는 기본적으로 Material Icons, Material Symbols, Font Awesome, Ionicons, MDI, Eva Icons, Themify Icons, Line Awesome, Bootstrap Icons을 지원해요.

게다가 어떤 아이콘 라이브러리든 직접 지원을 추가할 수도 있어요.

Quasar의 아이콘에는 여러 종류가 있어요: 웹폰트 기반, svg 기반, 이미지 기반이에요. 웹사이트/앱에서 한 종류만 쓰도록 제한되지는 않아요.

[!NOTE] 관련 페이지: Installing Icon Libraries와 Quasar Icon Sets.

출처: 문서

본문

QIcon API

Props

  • size (string, optional) Size in CSS units, including unit name or standard size name (xs|sm|md|lg|xl) Examples: '16px', '2rem', 'xs', 'md'
  • tag (string, optional), default 'i' HTML tag to render, unless no icon is supplied or it's an svg icon Examples: 'div', 'i'
  • name (string, optional) Icon name following Quasar convention; Make sure you have the icon library installed unless you are using 'img:' prefix; If 'none' (String) is used as value then no icon is rendered (but screen real estate will still be used for it) Examples: 'map', 'ion-add', 'img:https://cdn.quasar.dev/logo-v2/svg/logo.svg', 'img:path/to/some_image.png'
  • color (string, optional) Color name for component from the Quasar Color Palette Examples: 'primary', 'teal', 'teal-10'
  • left (boolean, optional) Useful if icon is on the left side of something: applies a standard margin on the right side of Icon
  • right (boolean, optional) Useful if icon is on the right side of something: applies a standard margin on the left side of Icon

Slots

  • #default Suggestions: QTooltip or QMenu

크기와 색상 (Size & colors)

QIcon의 크기는 font-size CSS 속성으로 조절돼요. 또 QIcon은 현재 CSS 텍스트 color도 상속해요. 편의를 위해 QIcon에는 size와 color prop이 있어요.

예시 "Basic":

<template>
  <div class="text-purple q-gutter-md" style="font-size: 2em">
    <q-icon name="font_download" />
    <q-icon name="warning" />
    <q-icon name="format_size" />
    <q-icon name="print" />
    <q-icon name="today" />
    <q-icon name="style" />
  </div>

  <div class="q-mt-md q-gutter-md">
    <q-icon name="font_download" color="primary" size="32px" />
    <q-icon name="warning" color="warning" size="4rem" />
    <q-icon name="format_size" style="color: #ccc; font-size: 1.4em" />
    <q-icon name="print" color="teal" size="4.4em" />
    <q-icon name="today" class="text-orange" size="2em" />
    <q-icon name="style" size="3em" />
  </div>
</template>

다른 Quasar 컴포넌트의 icon 속성에서는 플랫폼마다 아이콘을 따로 지정할 수단이 없지만, 아래와 같은 방식으로 같은 효과를 낼 수 있어요:

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

예시 "Standard sizes":

<template>
  <div class="text-purple q-gutter-md">
    <q-icon
      v-for="size in ['xs', 'sm', 'md', 'lg', 'xl']"
      :key="size"
      :size="size"
      name="font_download"
    />
  </div>
</template>

웹폰트 아이콘 (Webfont icons)

[!IMPORTANT] 웹폰트 기반 아이콘을 쓰는 경우, 사용 중인 아이콘 라이브러리를 설치했는지 확인하세요. 그렇지 않으면 아이콘이 표시되지 않아요!

웹폰트 사용 (Webfont usage)

<q-icon name="..." />
Quasar IconSet name Name prefix Examples Notes
material-icons None thumb_up Notice the underline character instead of dash or space
material-icons-outlined o_ o_thumb_up Notice the underline character instead of dash or space
material-icons-round r_ r_thumb_up Notice the underline character instead of dash or space
material-icons-sharp s_ s_thumb_up Notice the underline character instead of dash or space
material-symbols-outlined symo sym_o_thumb_up Notice the underline character instead of dash or space
material-symbols-rounded symr sym_r_thumb_up Notice the underline character instead of dash or space
material-symbols-sharp syms sym_s_thumb_up Notice the underline character instead of dash or space
ionicons-v4 ion-, ion-md-, ion-ios-, ion-logo- ion-heart, ion-logo-npm, ion-md-airplane Use QIcon instead of <ion-icon> component; Logo icons require 'ion-logo-' prefix
fontawesome-v7 fa-[solid,regular,brands] fa- "fa-solid fa-ambulance" QIcon "name" property is same as "class" attribute value in Fontawesome docs examples (where they show <i> tags)
fontawesome-v7 Pro fa-[solid,regular,brands,thin,light,duotone] fa- "fa-solid fa-ambulance" Note: a license must be purchased from Fontawesome for this functionality)
mdi-v7 mdi- mdi-alert-circle-outline Notice the use of dash characters
eva-icons eva- eva-shield-outline, eva-activity-outline Notice the use of dash characters
themify ti- ti-hand-point-up Notice the use of dash characters
line-awesome la[s,r,l,d,b] la- "las la-atom" QIcon "name" property is same as "class" attribute value in Line Awesome docs examples (where they show <i> tags); @quasar/extras v1.5+
bootstrap-icons bi- bi-bug-fill Notice the use of dash characters; @quasar/extras v1.10+

Material Symbols 변형 (Material Symbols variations)

Material Symbols에는 별도의 filled 폰트가 없어요. Outlined, Rounded, Sharp 폰트가 각각 fill(FILL), weight(wght), grade(GRAD), optical size(opsz) 변수 축을 노출해요. @quasar/extras가 제공하는 Material Symbols 웹폰트에는 이 축들이 포함돼 있어요.

개별 아이콘에서 이 축들을 제어할 수 있어요:

<q-icon
  name="sym_o_home"
  style="font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24"
/>

재사용 가능하고 런타임에 구성 가능한 변형을 원한다면 CSS 커스텀 속성을 Material Symbols 웹폰트 클래스로 스코프해 주세요:

.q-icon.material-symbols-outlined,
.q-icon.material-symbols-rounded,
.q-icon.material-symbols-sharp {
  font-variation-settings:
    'FILL' var(--material-symbol-fill, 0),
    'wght' var(--material-symbol-weight, 400),
    'GRAD' var(--material-symbol-grade, 0),
    'opsz' var(--material-symbol-optical-size, 24);
}

.q-icon.material-symbol-filled {
  --material-symbol-fill: 1;
}
<q-icon name="sym_o_home" />
<q-icon name="sym_o_home" class="material-symbol-filled" />

<q-icon
  name="sym_r_favorite"
  class="material-symbol-filled"
  style="--material-symbol-weight: 600; --material-symbol-grade: 100; --material-symbol-optical-size: 48"
/>

CSS 커스텀 속성은 아이콘별 변경, 상태 변경, 런타임 테마 적용을 가능하게 해요. 반면 Sass 변수는 빌드 시점에 고정된 프로젝트 전체 값만 필요할 때 사용하면 돼요.

[!NOTE] SVG 아이콘 세트

가변 폰트 축은 Material Symbols 웹폰트에만 적용돼요. @quasar/extras의 Material Symbols SVG 내보내기는 정적 path를 담고 있어 font-variation-settings로 바꿀 수 없어요.

명명 규칙 (Naming convention)

Material Icons (Google)

  • 아이콘 이름은 항상 snake_case예요.
  • Material Icons and Symbols에 가서 원하는 아이콘을 찾아보세요. 이름(예: "all_inbox")을 기억하고 그대로 쓰면 돼요.

MDI (Material Design Icons)

  • 아이콘 이름은 하이픈으로 구분된 형식이고 항상 "mdi-" 접두사로 시작해요.
  • MDI에 가서 원하는 아이콘을 찾아 클릭하면 대화 상자가 나타나요. 제목(예: "account-key")을 가져와서 "mdi-"를 붙이면 결과(예: "mdi-account-key")가 돼요.

Fontawesome

  • 아이콘 이름은 하이픈으로 구분된 형식이고 항상 "fas fa-", "fab fa-", "fal fa-" 또는 "far fa-" 접두사로 시작해요.
  • 최신 버전은 fa-solid, fa-brands, fa-light, fa-regular도 있어요(pro는 fa-thin, fa-duotone도 지원).
  • FontAwesome에 가서 원하는 아이콘을 찾아 클릭하면 그 페이지로 이동해요. 아이콘 이름(제목) 아래에서 <i class="fa-solid fa-flag"></i> 같은 것을 볼 수 있어요. 결과는 fa-solid fa-flag예요(fas fa-flag도 쓸 수 있어요).
  • 참고: fas, far, fab, fal, fat, fad는 폐기 예정이라 향후 메이저 버전에서는 없어질 수 있어요.

Ionicons

  • 아이콘 이름은 하이픈으로 구분된 형식이고 항상 "ion-", "ion-md-", "ion-ios-" 또는 "ion-logo-" 접두사로 시작해요.
  • Ionicons (v4)에 가서 원하는 아이콘을 찾아 클릭하면 페이지 맨 아래에 팝업이 나타나요. <ion-icon name="square-outline"></ion-icon> 같은 것을 볼 수 있어요. 이름(예: "square-outline")을 기억하세요. 원하는 변형(플랫폼 자동 감지, material, 또는 iOS)에 따라 결과는 ion-square-outline 또는 ion-md-square-outline 또는 ion-ios-square-outline이 돼요.
  • 참고: v5부터 Ionicons는 웹폰트를 더 이상 제공하지 않아요. Material이나 iOS 변형도 없어졌어요.

Eva Icons

  • 아이콘 이름은 하이픈으로 구분된 형식이고 항상 "eva-" 접두사로 시작해요.
  • Eva Icons에 가서 원하는 아이콘을 찾아 클릭하면 대화 상자가 나타나요. 거기서 이름(예: "attach-outline")을 가져와 "eva"를 붙이면 결과는 "eva-attach-outline"이 돼요.

Themify

  • 아이콘 이름은 하이픈으로 구분된 형식이고 항상 "ti-" 접두사로 시작해요.
  • Themify에 가서 원하는 아이콘을 찾아보세요. 이름(예: "ti-arrow-top-right")을 기억하고 그대로 쓰면 돼요.

Line Awesome

  • 아이콘 이름은 하이픈으로 구분된 형식이고 항상 "la" 접두사로 시작해요.
  • Line Awesome에 가서 원하는 아이콘을 찾아 클릭하면 대화 상자가 나타나요. <i class="lab la-behance-square"></i> 같은 것을 볼 수 있어요. 이름(예: "lab la-behance-square")을 기억하고 그대로 쓰면 돼요.

Bootstrap Icons

  • 아이콘 이름은 하이픈으로 구분된 형식이고 항상 "bi-" 접두사로 시작해요.
  • Bootstrap Icons에 가서 원하는 아이콘을 찾아보세요. 이름(예: "bi-bug-fill")을 기억하고 그대로 쓰면 돼요.

Svg 아이콘 (Svg icons)

웹사이트/앱에서 svg 아이콘만 사용하는 데는 많은 장점이 있어요:

  • 더 가벼운 앱 풋프린트 -- 사용된 아이콘만 최종 빌드에 포함돼요(treeshaking이 동작).
  • 더 좋은 품질의 아이콘
  • @quasar/extras나 CDN에서 해당 웹폰트를 포함할 필요가 없어요.

단점도 두 가지 있어요. 첫째, 이 아이콘들은 웹폰트에 비해 사용하기가 더 번거로워요. 둘째, svg 아이콘은 고정된 모양이라 variable icon 폰트(예: Material Symbols)의 축은 더 이상 조절할 수 없어요: font-variation-settings CSS 속성('FILL', 'wght', 'GRAD', 'opsz')은 웹폰트 아이콘에만 적용돼요. fill이나 weight를 바꿔야 한다면 아이콘 세트의 웹폰트 형태를, 더 작은 풋프린트가 필요하다면 svg 형태를 선택하세요.

Svg 사용 (Svg usage)

예시 ".vue 파일":

<template>
  <div>
    <q-icon :name="matMenu" />
    <q-icon :name="fasFont" />
    <q-btn :icon="mdiAbTesting" />
  </div>
</template>

<script setup>
  import { matMenu } from '@quasar/extras/material-icons'
  import { mdiAbTesting } from '@quasar/extras/mdi-v7'
  import { fasFont } from '@quasar/extras/fontawesome-v7'
</script>

:를 사용해 변수를 바인딩한다는 점에 주목하세요. 평범한 값이 아니라 변수 바인딩이 중요해요. 그 변수들을 템플릿에 사용할 수 있게 만들어야 해요. 그 방법은 여러분의 Vue API 선호에 따라 달라져요:

[!TIP] svg 아이콘만 사용한다면(그리고 Quasar Icon Set을 구성했다면) 앱에 웹폰트에 해당하는 것은 전혀 필요 없어요.

Vendor Quasar IconSet name Import Icons from Requirements
Material Icons (Google) svg-material-icons @quasar/extras/material-icons
Material Icons Outlined (Google) svg-material-icons-outlined @quasar/extras/material-icons-outlined @quasar/extras v1.9+;
Material Icons Sharp (Google) svg-material-icons-sharp @quasar/extras/material-icons-sharp @quasar/extras v1.9+
Material Icons Round (Google) svg-material-icons-round @quasar/extras/material-icons-round @quasar/extras v1.9+
Material Symbols Outlined (Google) svg-material-symbols-outlined @quasar/extras/material-symbols-outlined @quasar/extras v1.14+;
Material Symbols Sharp (Google) svg-material-symbols-sharp @quasar/extras/material-symbols-sharp @quasar/extras v1.14+
Material Symbols Round (Google) svg-material-symbols-rounded @quasar/extras/material-symbols-rounded @quasar/extras v1.14+
MDI (Material Design Icons) v3-v7 svg-mdi-v7 @quasar/extras/mdi-v7 etc @quasar/extras v1.11+
Font Awesome v7 svg-fontawesome-v7 @quasar/extras/fontawesome-v7 @quasar/extras v1.18+
Ionicons v8 svg-ionicons-v8 @quasar/extras/ionicons-v8 @quasar/extras v1.12+
Ionicons v4 svg-ionicons-v4 @quasar/extras/ionicons-v4
Eva Icons svg-eva-icons @quasar/extras/eva-icons
Themify Icons svg-themify @quasar/extras/themify
Line Awesome svg-line-awesome @quasar/extras/line-awesome @quasar/extras v1.5+
Bootstrap Icons svg-bootstrap-icons @quasar/extras/bootstrap-icons @quasar/extras v1.10+

가져오기 가이드 (Import guide)

svg 아이콘은 @quasar/extras가 제공해요(물론 여러분만의 svg 아이콘을 제공할 수도 있고요!). import 문법의 세세한 내용을 살펴볼게요:

SVG Material Icons (Google)

  • 아이콘 이름은 camel-case이고 항상 "mat" 접두사로 시작해요.
  • Material Icons에 가서 원하는 아이콘을 찾아 이름(예: "all_inbox")을 기억하고 "mat"을 붙인 뒤 camel-case로 바꾸면 돼요(예: "matAllInbox").
  • import 문 예시: import { matAllInbox } from '@quasar/extras/material-icons'.

SVG Material Icons Outlined (Google)

  • 아이콘 이름은 camel-case이고 항상 "outlined" 접두사로 시작해요.
  • Material Icons에 가서 원하는 아이콘을 찾아 이름(예: "all_inbox")을 기억하고 "outlined"를 붙인 뒤 camel-case로 바꾸면 돼요(예: "outlinedAllInbox").
  • import 문 예시: import { outlinedAllInbox } from '@quasar/extras/material-icons-outlined'.

SVG Material Icons Sharp (Google)

  • 아이콘 이름은 camel-case이고 항상 "sharp" 접두사로 시작해요.
  • Material Icons에 가서 원하는 아이콘을 찾아 이름(예: "all_inbox")을 기억하고 "sharp"를 붙인 뒤 camel-case로 바꾸면 돼요(예: "sharpAllInbox").
  • import 문 예시: import { sharpAllInbox } from '@quasar/extras/material-icons-sharp'.

SVG Material Icons Round (Google)

  • 아이콘 이름은 camel-case이고 항상 "round" 접두사로 시작해요.
  • Material Icons에 가서 원하는 아이콘을 찾아 이름(예: "all_inbox")을 기억하고 "round"를 붙인 뒤 camel-case로 바꾸면 돼요(예: "roundAllInbox").
  • import 문 예시: import { roundAllInbox } from '@quasar/extras/material-icons-round'.

SVG Material Symbols Outlined (Google)

  • 아이콘 이름은 camel-case이고 항상 "symOutlined" 접두사로 시작해요.
  • Material Icons에 가서 원하는 아이콘을 찾아 이름(예: "all_inbox")을 기억하고 "symOutlined"를 붙인 뒤 camel-case로 바꾸면 돼요(예: "symOutlinedAllInbox").
  • import 문 예시: import { symOutlinedAllInbox } from '@quasar/extras/material-symbols-outlined'.

SVG Material Symbols Sharp (Google)

  • 아이콘 이름은 camel-case이고 항상 "symSharp" 접두사로 시작해요.
  • Material Icons에 가서 원하는 아이콘을 찾아 이름(예: "all_inbox")을 기억하고 "symSharp"를 붙인 뒤 camel-case로 바꾸면 돼요(예: "symSharpAllInbox").
  • import 문 예시: import { symSharpAllInbox } from '@quasar/extras/material-symbols-sharp'.

SVG Material Symbols Rounded (Google)

  • 아이콘 이름은 camel-case이고 항상 "symRounded" 접두사로 시작해요.
  • Material Icons에 가서 원하는 아이콘을 찾아 이름(예: "all_inbox")을 기억하고 "symRounded"를 붙인 뒤 camel-case로 바꾸면 돼요(예: "symRoundedAllInbox").
  • import 문 예시: import { symRoundedAllInbox } from '@quasar/extras/material-symbols-rounded'.

SVG MDI (Material Design Icons)

  • 아이콘 이름은 camel-case이고 항상 "mdi" 접두사로 시작해요.
  • MDI에 가서 원하는 아이콘을 찾아 클릭하면 대화 상자가 나타나요. 제목(예: "account-key")을 가져와 "mdi"를 붙이고 camel-case로 바꾸면 돼요(예: "mdiAccountKey").
  • import 문 예시: import { mdiAccountKey } from '@quasar/extras/mdi-v7'.

SVG Fontawesome

  • 아이콘 이름은 camel-case이고 항상 "fas", "fab", "fal" 또는 "far" 접두사로 시작해요.
  • FontAwesome에 가서 원하는 아이콘을 찾아 클릭하면 그 페이지로 이동해요. 아이콘 이름(제목) 아래에서 <i class="fas fa-flag"></i> 같은 것을 볼 수 있어요. 이건 fasFlag로 변환돼요. 태그의 접두사가 중요해요.
  • 라이선스 때문에 "Pro" 버전의 아이콘은 svg 형식으로 제공할 수 없다는 점을 참고하세요.
  • import 문 예시: import { fasFlag } from '@quasar/extras/fontawesome-v7'.
  • Quasar의 svg 형태는 여전히 fas, far, fab을 사용해요. 최신의 fa-solid, fa-regular, fa-brands 대신이죠.

SVG Ionicons

  • Ionicons v4: 아이콘 이름은 camel-case이고 항상 "ionMd" 또는 "ionIos" 접두사로 시작해요.
  • Ionicons v8: 아이콘 이름은 camel-case이고 항상 "ion" 접두사로 시작해요.
  • Ionicons v4: Ionicons v4에 가서 원하는 아이콘을 찾아 클릭하면 페이지 맨 아래에 팝업이 나타나요. <ion-icon name="square-outline"></ion-icon> 같은 것을 볼 수 있어요. 이름(예: "square-outline")을 기억하세요. 이 이름을 camel-case로 바꾸고 "ionMd"(material 변형) 또는 "ionIos"(iOS 변형)를 접두사로 붙이세요.
  • Ionicons v5/v6: Ionicons v6에 가서 원하는 아이콘을 찾아 클릭하면 페이지 맨 아래에 팝업이 나타나요. <ion-icon name="square-outline"></ion-icon> 같은 것을 볼 수 있어요. 이름(예: "square-outline")을 기억하세요. "ion"을 붙이고 camel-case로 바꾸면 돼요(예: "ionSquareOutline").
  • Ionicons v4: import 문 예시: import { ionMdSquareOutline } from '@quasar/extras/ionicons-v4'.
  • Ionicons v8: import 문 예시: import { ionSquareOutline } from '@quasar/extras/ionicons-v8'.

SVG Eva Icons

  • 아이콘 이름은 camel-case이고 항상 "eva" 접두사로 시작해요.
  • Eva Icons에 가서 원하는 아이콘을 찾아 클릭하면 대화 상자가 나타나요. 거기서 이름(예: "attach-outline")을 가져와 "eva"를 붙이고 camel-case로 바꾸면 돼요(예: "evaAttachOutline").
  • import 문 예시: import { evaAttachOutline } from '@quasar/extras/eva-icons'.

SVG Themify

  • 아이콘 이름은 camel-case이고 항상 "ti" 접두사로 시작해요.
  • Themify에 가서 원하는 아이콘을 찾아보세요. 이름(예: "ti-arrow-top-right")을 기억하고 "ti"를 붙인 뒤 camel-case로 바꾸면 돼요(예: "tiArrowTopRight").
  • import 문 예시: import { tiArrowTopRight } from '@quasar/extras/themify'.

SVG Line Awesome

  • 아이콘 이름은 camel-case이고 항상 "la" 접두사로 시작해요.
  • Line Awesome에 가서 원하는 아이콘을 찾아 클릭하면 대화 상자가 나타나요. <i class="lab la-behance-square"></i> 같은 것을 볼 수 있어요. 이건 laBehanceSquare로 변환돼요. 다만 특별한 경우가 있어요(솔리드 아이콘만!): "la-" 앞의 접두사가 "las"라면(예: <i class="las la-atom"></i>) "la-atom"에 "-solid"를 붙이고 camel-case로 바꾸면 돼요(예: laAtomSolid).
  • import 문 예시: import { laBehanceSquare } from '@quasar/extras/line-awesome'.

SVG Bootstrap Icons

  • 아이콘 이름은 camel-case이고 항상 "bi" 접두사로 시작해요.
  • Bootstrap Icons에 가서 원하는 아이콘을 찾아보세요. 이름(예: "bi-bug-fill")을 기억하고 camel-case로 바꾸면 돼요(예: "biBugFill").
  • import 문 예시: import { biBugFill } from '@quasar/extras/bootstrap-icons'.

Svg 아이콘 형식 (Svg icon format)

여러분만의 svg 아이콘도 제공할 수 있어요. svg 아이콘은 본질적으로 다음 문법을 가진 String이에요:

Syntax: "<path>&&<path>&&...|<viewBox>"
           P       P             V
                (optional)   (optional)
                             (default: 0 0 24 24)

P is a path tag with following syntax (each are attributes):
        "<d>@@<style>@@<transform>"
        (required)
            (optional)
                     (optional)

예시:

// Simplest ("<path>"):
  M9 3L5 6.99h3V14h2V6.99h3L9 3zm7 14.01V10h-2v7.01h-3L15 21l4-3.99h-3z

// equivalent to:
<svg viewBox="0 0 24 24">
  <path d="M9 3L5 6.99h3V....."/>
</svg>
// Simplest with custom viewBox ("<path>|<viewBox>"):
  M9 3L5 6.99h3V14h2V6.99h3L9 3zm7 14.01V10h-2v7.01h-3L15 21l4-3.99h-3z|0 0 104 104

// equivalent to:
<svg viewBox="0 0 104 104">
  <path d="M9 3L5 6.99h3V....."/>
</svg>
// Path with custom style ("<path>@@<style>|<viewBox>"):
  M48,96L464,96 464,416 48,416z@@fill:none;stroke:currentColor.....|0 0 512 512

// equivalent to:
<svg viewBox="0 0 512 512">
  <path d="M416,480,256,357....." style="fill:none;stroke:curren..." />
</svg>
// Path with custom style and transform ("<path>@@<style>@@transform"):
  M9 3L5 6.99h3V...@@fill:none;stroke:cu.....@@translate(10 1) rotate(180)

// equivalent to:
<svg viewBox="0 0 24 24">
  <path
    d="M9 3L5 6.99h3V....."
    style="fill:none;stroke:curren..."
    transform="translate(10 1) rotate(180)"
  />
</svg>
// Path with custom transform ("<path>@@@@transform"):
// (Notice style separator is still specified)

  M9 3L5 6.99h3V...@@@@translate(2 4) rotate(180)

// equivalent to:
<svg viewBox="0 0 24 24">
  <path
    d="M9 3L5 6.99h3V....."
    transform="translate(2 4) rotate(180)"
  />
</svg>
// Multi-paths -- any number of paths are possible ("<path>&&<path>|<viewBox>"):
  M416,480,256,357.41,96,480V32H416Z&&M368,64L144 256 368 448 368 64z|0 0 512 512

// equivalent to:
<svg viewBox="0 0 512 512">
  <path d="M416,480,256,357....." />
  <path d="M368,64L144 256 368...." />
</svg>
// Multi-paths, each with style and transform ("<path>&&<path>|<viewBox>"):
  M9 3L5 6.99h3V...@@stroke-width:5px@@rotate(45)&&M416,480,256,...@@stroke-width:2px@@rotate(15)&&M368,64L144 2...@@stroke-width:12px@@rotate(5)|0 0 512 512

// equivalent to:
<svg viewBox="0 0 512 512">
  <path
    d="M9 3L5 6.99h3V....."
    style="stroke-width:5px"
    transform="rotate(45)"
  />
  <path
    d="M416,480,256,..."
    style="stroke-width:2px"
    transform="rotate(15)"
  />
  <path
    d="M368,64L144 2..."
    style="stroke-width:12px"
    transform="rotate(5)"
  />
</svg>

SVG-use 방식 (SVG-use way)

이 svg 방식은 SVG 파일을 정적 자산으로 저장하고 참조할 수 있게 해 줘요.

예시 "/public/icons.svg":

<svg xmlns="http://www.w3.org/2000/svg">
  <symbol id="icon-1" viewBox="0 0 24 24">
    <path d="..."></path>
  </symbol>
  <symbol id="icon-2" viewBox="0 0 24 24">
    <path d="..."></path>
  </symbol>
</svg>

표준 HTML 방식은 파일을 포함하고 svg use 태그로 아이콘을 지정하는 거예요.

<svg>
  <use xlink:href="icons.svg#icon-1"></use>
</svg>

이걸 QIcon을 통해 Quasar와 함께 사용하려면(public 폴더에서 올바른 파일을 참조하고 있는지 확인하세요):

<q-icon name="svguse:icons.svg#icon-1">
  <!-- or -->
  <q-btn-dropdown
    label="Custom Content"
    dropdown-icon="svguse:icons.svg#icon-2"
/></q-icon>

기본적으로 부모 svg의 viewBox는 "0 0 24 24"예요. 하지만 커스텀 뷰박스를 지정할 수도 있어요:

<q-icon name="svguse:icons.svg#icon-1|10 15 40 40" />

인라인 svg (Inlined svg)

위의 웹폰트나 svg 변형을 쓰고 싶지 않다면, QIcon이 하나의 인라인 <svg> 태그(내용은 path뿐 아니라 무엇이든 될 수 있어요)도 지원한다는 점을 참고하세요.

QIcon에서 <svg>를 쓰는 이유는, svg가 그 props를 통해 다른 QIcon처럼 크기와 색상을 따르기 때문이에요. 이런 기능이 없다면 QIcon으로 감싸지 않고 템플릿에 직접 svg를 인라인하는 것이 더 나아요.

<q-icon color="accent" size="5rem">
  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
    <path d="M0 0h24v24H0z" fill="none" />
    <path
      d="M19 3h-4.18C14.4 1.84 13.3 1 12 1c-1.3 0-2.4.84-2.82 2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-7 0c.55 0 1 .45 1 1s-.45 1-1 1-1-.45-1-1 .45-1 1-1zm0 4c1.66 0 3 1.34 3 3s-1.34 3-3 3-3-1.34-3-3 1.34-3 3-3zm6 12H6v-1.4c0-2 4-3.1 6-3.1s6 1.1 6 3.1V19z"
    />
  </svg>
</q-icon>

몇 가지 제한 사항이 있어요:

  • <svg> 태그에 "height"/"width" 속성을 쓰지 마세요(QIcon의 크기 처리 방식이 깨져요).
  • 모든 <path>에는 기본적으로 "fill: currentColor" CSS가 적용돼요. 이걸 원하지 않으면 <path> 태그에 fill="none"을 추가하세요.

이미지 아이콘 (Image icons)

webfont에 의존하지 않고 아이콘이 이미지 URL을 가리키도록 하려면 img: 접두사를 사용할 수도 있어요.

Quasar 컴포넌트의 모든 아이콘 관련 prop이 이것을 사용할 수 있어요.

<q-icon name="img:https://cdn.example.com/logo.svg" />
<q-btn icon="img:https://cdn.example.com/logo.svg" ... />

이것은 SVG에만 국한되지 않아요. 원하는 이미지 타입(png, jpg, ...)을 쓸 수 있어요:

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

public 폴더 이미지 (Public folder images)

/public 폴더에 있는 이미지는 그대로 제공돼요. 그래서 루트 상대 URL(앞에 /)로 가리키면 돼요. img:icons/my.svg 같은 순수 상대 URL은 피하세요: 브라우저가 현재 페이지 URL 기준으로 해석하기 때문에 중첩된 라우트에서 깨져요.

<!-- /public/icons/my.svg -->
<q-icon name="img:/icons/my.svg" />

앱이 서브 경로 아래에 배포된다면 Handling Assets 페이지에서 설명한 대로 URL 앞에 import.meta.env.BASE_URL을 붙여 주세요.

번들된 이미지 (Bundled images)

<img src>나 QImg src에서 동작하는 ~와 @ 접두사는 아이콘 prop 안에서는 동작하지 않아요. Vite(Vue 컴파일러를 통해)는 전체 값이 ., ~, @로 시작할 때만 속성을 import로 재작성하는데, 앞의 img: 접두사가 그걸 막아요. img:~assets/my.svg 같은 아이콘은 브라우저가 그대로 요청해서 실패해요.

/src/assets(또는 Vite가 번들하는 다른 곳)에 있는 이미지를 쓰려면 import해서 prop에 바인딩하세요:

<template>
  <q-btn :icon="`img:${myIcon}`" />
</template>

<script setup>
import myIcon from 'assets/my.svg'
</script>

인라인 이미지 (Inline images)

이미지(svg, png, jpeg, gif...)를 인라인하고 그 스타일(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":

<template>
  <div class="row no-wrap items-center justify-around">
    <q-icon size="100px" :name="girlSvg" />

    <q-btn
      :dense="$q.screen.xs"
      no-caps
      label="Face"
      icon-right="colorize"
      color="primary"
    >
      <q-popup-proxy cover transition-show="scale" transition-hide="scale">
        <q-color v-model="colorFace" />
      </q-popup-proxy>
    </q-btn>

    <q-btn
      :dense="$q.screen.xs"
      no-caps
      label="Hair"
      icon-right="colorize"
      color="secondary"
    >
      <q-popup-proxy cover transition-show="scale" transition-hide="scale">
        <q-color v-model="colorHair" />
      </q-popup-proxy>
    </q-btn>
  </div>
</template>

<script setup>
import { computed, ref } from 'vue'

const colorFace = ref('#B33636')
const colorHair = ref('#FFD700')

const girlSvg = computed(() => {
  const face = colorFace.value.replace('#', '%23')
  const hair = colorHair.value.replace('#', '%23')
  return `img:data:image/svg+xml;charset=utf8,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" stroke="none" fill="${face}"><path fill="none" d="M0 0h24v24H0V0z"/><path stroke="${hair}" fill="${hair}" stroke-linecap="round" opacity=".5" d="M17.5 8c.46 0 .91-.05 1.34-.12C17.44 5.56 14.9 4 12 4c-.46 0-.91.05-1.34.12C12.06 6.44 14.6 8 17.5 8zM8.08 5.03C6.37 6 5.05 7.58 4.42 9.47c1.71-.97 3.03-2.55 3.66-4.44z"/><path stroke="none" fill="${face}" stroke-linecap="round"  d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 2c2.9 0 5.44 1.56 6.84 3.88-.43.07-.88.12-1.34.12-2.9 0-5.44-1.56-6.84-3.88.43-.07.88-.12 1.34-.12zM8.08 5.03C7.45 6.92 6.13 8.5 4.42 9.47 5.05 7.58 6.37 6 8.08 5.03zM12 20c-4.41 0-8-3.59-8-8 0-.05.01-.1.01-.15 2.6-.98 4.68-2.99 5.74-5.55 1.83 2.26 4.62 3.7 7.75 3.7.75 0 1.47-.09 2.17-.24.21.71.33 1.46.33 2.24 0 4.41-3.59 8-8 8z"/><circle cx="9" cy="13" r="1.25"/><circle cx="15" cy="13" r="1.25"/></svg>`
})
</script>

이미지를 base64로 인코딩해서 제공할 수도 있어요. 아래 예시는 QBtn이지만, 어떤 아이콘 prop이나 QIcon에서도 같은 원리가 적용돼요:

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

커스텀 매핑 (Custom mapping)

원한다면 아이콘 이름의 매핑을 커스터마이징할 수 있어요. 커스텀 아이콘 맵 함수를 제공하면 되는데, 여러 가지 방법이 있어요:

  • 엔트리 파일에서 IconSet.iconMapFn 설정:
  • Quasar CLI(Vite)를 쓴다면 boot 파일에서:
  • Quasar Vite 플러그인을 쓴다면 main.js/main.ts(또는 비슷한 곳)에서:
  • UMD를 쓴다면 적절한 파일이나 script 태그에서:
  • 루트 컴포넌트(예: App.vue)에서 $q.iconMapFn 설정:
  • Composition API를 <script setup>과 함께 쓴다면 최상위에서:
  • Composition API를 쓴다면 setup() 함수에서:
  • Options API를 쓴다면 created() 훅에서:
  • Quasar Vue 플러그인 옵션 > config에서 iconMapFn 설정(Quasar CLI 외의 flavor), 예: app.use(Quasar, { config: { iconMapFn } }).

아래 사용 사례 예시에서는 <script setup>을 쓴 $q.iconMapFn 방식을 사용할 건데, 다른 방법에도 같은 원리가 적용돼요.

iconMapFn의 구조는 다음과 같아요:

type GlobalQuasarIconMapFn = (iconName: string) =>
  // Map to another existing icon
  | {
      icon: string // the mapped icon string, which will be handled
      // by Quasar as if the original QIcon name was this value
    }
  // Define how to interpret the 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
    }
  // Leave it as is, default Quasar handling
  | void

아이콘 매핑은 QIcon만이 아니라 QBtn, QInput 등 아이콘을 사용하는 다른 모든 Quasar 컴포넌트에도 영향을 미쳐요.

여러분의 iconMapFn은 순수 매핑(pure mapping)이어야 해요: Quasar는 성능상 함수별로 결과를 캐시해요. 매핑을 런타임에 바꾸려면 $q.iconMapFn에 새 함수를 할당하면 렌더링된 아이콘이 그것을 반영해요 — 이미 할당된 함수 뒤의 상태를 변경하는 것은 캐시 때문에 반영되지 않아요.

사용 사례 1: 아이콘 몇 개를 단순하게 매핑하기 (Use case 1)

import { useQuasar } from 'quasar'

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

// ...
const $q = useQuasar()

$q.iconMapFn = iconName => {
  const icon = myIcons[iconName]
  if (icon !== undefined) {
    return { icon }
  }
}

이제 <q-icon name="app:copy" />나 <q-icon name="app:icon1" />을 쓸 수 있고, QIcon은 "app:copy"와 "app:icon1"을 각각 "fas fa-copy"와 "img:/path/to/icon1.svg"로 쓴 것처럼 취급해요. 아이콘을 사용하는 다른 Quasar 컴포넌트에도 동일하게 적용돼요. 예: <q-btn icon="app:copy" />.

사용 사례 2: 커스텀 아이콘 라이브러리 지원 (Use case 2)

커스텀 아이콘 라이브러리(Quasar와 그 @quasar/extras 패키지에 없는)를 사용할 때 특히 유용해요.

import { useQuasar } from 'quasar'

const $q = useQuasar()

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

$q.iconMapFn = iconName => {
  // iconName is the content of QIcon "name" prop (or related icon prop of other Quasar components)

  // can be any logic you want, but for this example:
  if (iconName.startsWith('app:')) {
    // 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
}

위 예시에서 아이콘이 app: 접두사로 시작하면 QIcon에 적용되는 my-app-icon 클래스를 반환한다는 점을 주목하세요. 이걸 사용해 CSS 관점에서 QIcon이 어떻게 반응할지 정의할 수 있어요.

"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');
}

그런 다음 새로 만든 CSS 파일을 앱에 추가해야 해요:

  • Quasar CLI: quasar.config 파일의 css 배열에 추가하세요.
// quasar.config file
css: [
  // ....
  'my-app-icon.css'
]
  • 기타: CSS 파일에 추가하고 main.js/main.ts에서 import하거나 HTML 파일에 포함하세요:
// in your main.js/main.ts
import '@/css/my-app-icon.css'

// or in the main css file
@import url('./my-app-icon.css');

// or in your HTML file (UMD)
<link rel="stylesheet" href="/css/my-app-icon.css">

그리고 "my-app-icon.woff2"와 "my-app-icon.woff" 파일을 "my-app-icon.css"와 같은 폴더에 추가하세요(다른 곳에 둬도 되지만, woff/woff2 파일까지의 상대 경로(위 "src:" 참고)를 수정해야 해요).

접근성 (Accessibility) (v2.25+)

모든 QIcon은 aria-hidden="true"로 렌더링돼요 — 아이콘은 기본적으로 장식용으로 취급되며, 여기에는 웹폰트 합자(ligature) 텍스트도 포함돼요(스크린 리더가 "home"을 읽지 않아요). 드물게 자체 의미를 지닌 단독 아이콘은 속성으로 덮어쓰면 돼요: aria-hidden="false"와 함께 role="img"와 aria-label을 주세요.

합자 기반 세트(Material Icons와 Material Symbols)에서는 합자 텍스트 자체가 별도의 aria-hidden 요소로 감싸져요. 그래서 대화형 컨트롤 역할을 하는 아이콘(예: clearable 필드의 지우기 동작 — aria-hidden을 덮어쓰고 role="button"과 aria-label을 가진)조차 원시 합자(예: "cancel")를 접근 가능한 이름과 경쟁하는 콘텐츠로 노출하지 않아요(WCAG 2.5.3). 클래스 기반 세트(FontAwesome, MDI 등)는 실제 텍스트 콘텐츠를 렌더링하지 않으므로 래퍼가 필요 없고, 그렇게 되어 있어요.

버튼이나 링크 안의 아이콘은 그 컨트롤의 접근 가능한 이름에 기여하지 않아요 — 아이콘을 라벨링하기보다 컨트롤 자체를 라벨링하세요(예: QBtn의 aria-label).

더 알아보기 (Learn more)