Integrations
Svelte

Svelte

The @hugeicons/svelte package is freely available on the public npm registry. To use HugeIcons in your Svelte project, you'll need to install both the Svelte component package and at least one icon package of your choice. This modular approach allows you to keep your bundle size minimal by including only the icons you plan to use.

Installation

  1. Install the Svelte component package:
npm install @hugeicons/svelte
  1. Install your preferred icon package(s):
npm install @hugeicons-pro/core-{variant}-{style}

Available styles:

HugeIcons Pro offers 36,000+ icons across 9 unique styles:

# Stroke Styles (Line icons with different corner styles)
@hugeicons-pro/core-stroke-rounded
@hugeicons-pro/core-stroke-sharp
@hugeicons-pro/core-stroke-standard
 
# Solid Styles (Filled icons with different corner styles)
@hugeicons-pro/core-solid-rounded
@hugeicons-pro/core-solid-sharp
@hugeicons-pro/core-solid-standard
 
# Special Styles (Unique visual treatments)
@hugeicons-pro/core-bulk-rounded      # Chunky style with depth
@hugeicons-pro/core-duotone-rounded   # Two-color design with primary/secondary emphasis
@hugeicons-pro/core-twotone-rounded   # Alternative two-color treatment

For more detailed information about our core packages and available styles, please visit our Core Packages page.

Basic Usage

<script>
  import { HugeiconsIcon } from '@hugeicons/svelte'
  import { Notification03Icon } from '@hugeicons-pro/core-stroke-rounded'
</script>
 
<HugeiconsIcon
  icon={Notification03Icon}
  size={24}
  color="currentColor"
  strokeWidth={1.5}
/>

Props

PropTypeDefaultDescription
iconIconSvgObjectRequiredThe main icon component imported from an icon package
altIconIconSvgObject-Alternative icon component from an icon package for states, interactions, or animations
showAltbooleanfalseWhen true, displays the altIcon instead of the main icon
sizenumber24Icon size in pixels
colorstringcurrentColorIcon color (CSS color value)
strokeWidthnumber1.5Width of the icon strokes (works with stroke-style icons)
classstring-Additional CSS classes

Icon Naming

Each icon in our packages can be imported using either its main name or its style-specific alias:

// Both imports refer to the same icon
import { SearchIcon } from '@hugeicons-pro/core-stroke-rounded'
import { SearchStrokeRounded } from '@hugeicons-pro/core-stroke-rounded'

We recommend using the shorter main name (e.g., SearchIcon) for better readability. The style-specific aliases are useful when importing the same icon from different style packages to avoid naming conflicts.

Examples of Dynamic Icon Interactions

Search Bar with Clear Button

A search input that shows a clear button when text is entered:

<script>
  import { HugeiconsIcon } from '@hugeicons/svelte'
  import { SearchIcon, CloseCircleIcon } from '@hugeicons-pro/core-stroke-rounded'
 
  let searchValue = ''
</script>
 
<div>
  <input
    bind:value={searchValue}
    type="text"
    placeholder="Search..."
  />
  <HugeiconsIcon
    icon={SearchIcon}
    altIcon={CloseCircleIcon}
    showAlt={searchValue.length > 0}
    on:click={() => searchValue.length > 0 ? searchValue = '' : null}
  />
</div>

Theme Toggle with Style Switch

A simple dark mode toggle using different icons:

<script>
  import { HugeiconsIcon } from '@hugeicons/svelte'
  import { SunIcon, Moon02Icon } from '@hugeicons-pro/core-solid-rounded'
 
  let isDark = false
</script>
 
<button on:click={() => isDark = !isDark}>
  <HugeiconsIcon
    icon={SunIcon}
    altIcon={Moon02Icon}
    showAlt={isDark}
  />
</button>

Navigation Bar with Style Switch

A navigation bar that uses different icon styles to indicate the active state:

<script>
  import { HugeiconsIcon } from '@hugeicons/svelte'
  import { 
    HomeIcon,
    SearchIcon,
    Notification03Icon,
    UserIcon 
  } from '@hugeicons-pro/core-solid-rounded'
  import {
    HomeIcon as HomeDuotone,
    SearchIcon as SearchDuotone,
    Notification03Icon as NotificationDuotone,
    UserIcon as UserDuotone
  } from '@hugeicons-pro/core-duotone-rounded'
 
  let activeTab = 'home'
 
  const navItems = [
    { id: 'home', solidIcon: HomeIcon, duotoneIcon: HomeDuotone },
    { id: 'search', solidIcon: SearchIcon, duotoneIcon: SearchDuotone },
    { id: 'notifications', solidIcon: Notification03Icon, duotoneIcon: NotificationDuotone },
    { id: 'profile', solidIcon: UserIcon, duotoneIcon: UserDuotone }
  ]
</script>
 
<nav>
  {#each navItems as item}
    <button
      on:click={() => activeTab = item.id}
      class:active={activeTab === item.id}
    >
      <HugeiconsIcon
        icon={item.solidIcon}
        altIcon={item.duotoneIcon}
        showAlt={activeTab === item.id}
        size={24}
      />
    </button>
  {/each}
</nav>