<c-icon>
An icon drawn from a single SVG path, sized in pixels and filled with the colour of the surrounding text unless given one of its own.
Usage
Pass the icon path in path: the path data of an icon drawn on a 24×24 grid,
typically an export of @mdi/js (Material Design Icons). The icon renders at
24px; size sets another width and height in pixels.
In the icon slot of another component, such as c-button, c-menu-item or
c-status, leave size unset: the component sizes the icon to match.
c-status sizes it whatever its size; elsewhere a size of its own wins.
<script setup lang="ts">
import { mdiCheckCircle } from '@mdi/js';
</script>
<template>
<c-icon :path="mdiCheckCircle" :size="20" />
</template>
Colour
Without color, the icon fills with currentColor, so it takes the text
colour of its surroundings: inside a c-button or c-icon-button it follows
the button's appearance and disabled state. To recolour it, set the CSS
color on the element or an ancestor, or pass any CSS colour in color.
Prefer the semantic tokens, such as color="var(--c-success)", which follow
the theme mode.
Accessibility
The icon is an unnamed <svg> unless the element has an aria-label.
- A decorative icon, one beside a visible label that says the same thing:
set
aria-hidden="true"on thec-iconso screen readers skip it. - Inside a control named by its
aria-label, such as ac-icon-button, the label replaces the icon; nothing more is needed. - A meaningful icon with no visible text, such as a status shown only as an
icon: name it with
aria-labelon thec-icon, which makes it an image (role="img") with that name.
<c-icon
:path="mdiCheckCircle"
aria-label="Completed"
color="var(--c-success)"
/>
Customization
::part(root) is the <svg>. Its width and height are set inline from
size, or from the icon slot it sits in, so size the icon with the prop. A color set on the part recolours
an icon that has no color prop of its own.
Examples
<template>
<div class="example-row">
<c-icon :path="mdiAccount" />
<c-icon :path="mdiBellOutline" size="36" />
<c-icon :path="mdiCheckCircle" color="var(--c-success)" size="36" />
</div>
</template>
<script setup lang="ts">
import { mdiAccount, mdiBellOutline, mdiCheckCircle } from '@mdi/js';
</script>
API reference
<c-icon>
An icon drawn from a single SVG path, sized in pixels and filled with the colour of the surrounding text unless given one of its own.
Properties
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
color | color | string | 'currentColor' | Fill color. |
path | path | string | — | Svg `path` `d` attribute value. |
size | size | number | 24 | Icon size in pixels. Unset, the icon takes the size of the icon slot it sits in. |
CSS parts
Style from outside with c-icon::part(name) — parts are the library's only styling customization API.
| Part | Description |
|---|---|
root | The `<svg>` element rendering the icon |