Skip to content
Likable Aurora @likable-hair/svelte 5

Icon

SVG icon from a path on a 24×24 viewBox, for example from @mdi/js. It inherits color and size from the surrounding text (--icon-size and --icon-color change them). Without title it is decorative and hidden from screen readers. It is not clickable: for a clickable icon use Button with buttonType="text", icon and aria-label.

import { Icon } from '@likable-hair/svelte';

src/lib/components/simple/media/Icon.svelte · Markdown for LLMs

Basic

The icon takes an SVG path (24×24 viewBox), for example from @mdi/js. It inherits color and size from the surrounding text; without title it is decorative.

Favorite
Code
<script lang="ts">
	import { mdiCalendarOutline, mdiHeart, mdiMagnify } from '@mdi/js';
	import { Icon } from '@likable-hair/svelte';
</script>

<Icon path={mdiMagnify} />
<Icon path={mdiCalendarOutline} --icon-size="32px" />
<Icon path={mdiHeart} title="Favorite" --icon-size="32px" --icon-color="var(--global-color-error)" />

Clickable icon

Icon is only an image. For a clickable icon use Button with buttonType="text": focus, keyboard, hover and disabled work correctly. Without text it needs an aria-label.

Code
<script lang="ts">
	import { mdiClose, mdiPencilOutline, mdiTrashCanOutline } from '@mdi/js';
	import { Button } from '@likable-hair/svelte';
</script>

<Button buttonType="text" variant="secondary" icon={mdiClose} aria-label="Close" />
<Button buttonType="text" icon={mdiPencilOutline} aria-label="Edit" />
<Button buttonType="text" variant="danger" icon={mdiTrashCanOutline} aria-label="Delete" />
<Button buttonType="text" variant="secondary" size="sm" icon={mdiClose} aria-label="Close" disabled />

Props

NameTypeDefaultDescription
path requiredstringSVG path on a 24×24 viewBox, for example from @mdi/js (import { mdiPlus } from '@mdi/js').
title stringAccessible name. Without it the icon is decorative and hidden from screen readers.
class string''Extra classes on the <svg> element.

CSS variables

For a single instance, pass them as style props: <Icon --icon-color="tomato">. The --icon-default-* defaults apply to the whole app: override them in :root or in a theme.

Per-instance variableDefault
--icon-size
--icon-default-size 1em
--icon-color
--icon-default-color currentColor