Getting Started - Svelte Flag Icons v1

sponsor npm License npm

Requirements #

You need to use the following:

- Svelte 4 or 5 (without Runes)

Installation #

Install Svelte and Svelte Flag Icons:

npm create svelte@latest my-project
cd my-project
pnpm i -D svelte-flag-icons

Basic Usage #

In a svelte file:

<script>
  import { Us } from 'svelte-flag-icons';
</script>

<Us />

aria-label #

Use ariaLabel props to edit the aria-label.

<Us
  ariaLabel="American flag, 13 stripes, 50 stars"
/>

IDE support #

If you are using an LSP-compatible editor, such as VSCode, Atom, Sublime Text, or Neovim, hovering over a component name will display a documentation link, features, props, events, etc.

Faster compiling #

If you need only a few icons from this library in your Svelte app, import them directly. This can optimize compilation speed and improve performance by reducing the amount of code processed during compilation.

<script>
  import Us from 'svelte-flag-icons/Us.svelte';
</script>

<Us />

Passing down other attributes #

Since all icons have ...$$restProps, you can pass other attibutes as well.

<Us id="my-svg" transform="rotate(45)" />

Using svelte:component #

<script>
  import { Us } from 'svelte-flag-icons';
</script>

<svelte:component this="{Us}" />

Using onMount #

<script>
  import { Us } from 'svelte-flag-icons';
  import { onMount } from 'svelte';
  const props = {
    size: '50',
    // other props
  };
  onMount(() => {
    const icon = new Us({ target: document.body, props });
  });
</script>

Import all #

Use `import * as Icon from 'svelte-flag-icons`.

<script>
  import * as Icon from 'svelte-flag-icons';
</script>

<Icon.Us />
<Icon.Us size="30" />