Getting Started - Flowbite Svelte Icons v1
Requirements #
You need to use the following:
- Svelte 4 or 5
- TailwindCSS
Installation #
Install Svelte and TailwindCSS:
npm create svelte@latest myapp
cd myapp
npx svelte-add@latest tailwindcss
pnpm i -D flowbite-svelte-icons@v1-latest
To make sure the classes used by flowbite-svelte-icons are included by the Tailwindcss, add the following to tailwind.config.cjs.
const config = {
content: [
// more lines
"./node_modules/flowbite-svelte-icons/**/*.{html,js,svelte,ts}",
],
// more lines
}
Basic Usage #
In a svelte file:
<script>
import { AddressBookOutline } from 'flowbite-svelte-icons';
</script>
<AddressBookOutline />
A11y friendly #
Use title
, desc
, and ariaLabel
props to make your icons accessible.
<HeartSolid
title={{ id: 'my-title', title: 'Red heart' }}
desc={{ id: 'my-description', desc: 'The shape of a red heart' }}
ariaLabel="red heart"
color="red"
/>
Check out this icon in the console:
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 AddressBookOutline from 'flowbite-svelte-icons/AddressBookOutline.svelte';
</script>
<AddressBookOutline />
Passing down other attributes #
Since all icons have ...$$restProps
, you can pass other attibutes as well.
<AddressBookOutline id="my-svg" transform="rotate(45)"/>
Using svelte:component #
<script>
import { AddressBookOutline } from 'flowbite-svelte-icons';
</script>
<svelte:component this="{AddressBookOutline}" />
Using onMount #
<script>
import { AddressBookOutline } from 'flowbite-svelte-icons';
import { onMount } from 'svelte';
const props = {
size: '50',
color: '#ff0000'
};
onMount(() => {
const icon = new AddressBookOutline({ target: document.body, props });
});
</script>
Import all #
Use import * as Icon from 'svelte-awesome-icons
.
<script>
import * as Icon from 'flowbite-svelte-icons';
</script>
<Icon.AddressBookOutline />
<h1>Size</h1>
<Icon.AddressBookOutline size="xl" />
<h1>Tailwind CSS</h1>
<Icon.AddressBookOutline class="text-blue-500" />