Svelte Player
Learn how to quickly integrate the dotLottie Svelte component into your Svelte or SvelteKit application. Covers installation and basic usage.
Getting Started with the Svelte Player
In this tutorial, you will install and configure the Svelte player to display your first Lottie animation in a Svelte or SvelteKit application.
Prerequisites
Working Svelte/SvelteKit development environment.
Node.js and npm or yarn installed.
Installation
Install the package using your preferred package manager:
# Using npm
npm install @lottiefiles/dotlottie-svelte
# Using yarn
yarn add @lottiefiles/dotlottie-svelteBasic Usage Example
Here's a simple Svelte component demonstrating how to import and use the player:
<script>
import { DotLottieSvelte } from "@lottiefiles/dotlottie-svelte";
</script>
<main>
<h1>Svelte Animation</h1>
<DotLottieSvelte
src="https://lottie.host/your-animation-id.lottie" // Replace with your animation URL
autoplay
loop
style="width: 300px; height: 300px; border: 1px solid #eee;"
/>
</main>
<style>
main {
text-align: center;
padding: 1em;
}
h1 {
color: #ff3e00;
text-transform: uppercase;
font-size: 2em;
font-weight: 100;
}
</style>Explanation:
Import: Import the
DotLottieSveltecomponent in the<script>tag.Use Component: Render the
<DotLottieSvelte />component in your template.Props:
src: Required URL or path to your.lottieor.jsonfile.autoplay: Boolean prop (shorthand forautoplay={true}) to start playing immediately.loop: Boolean prop (shorthand forloop={true}) to repeat the animation.style: Standard HTML style attribute for basic sizing and styling.
Automatic Cleanup
The DotLottieSvelte component automatically handles the cleanup (calling destroy() on the core player instance) when the Svelte component is destroyed, preventing memory leaks.
Next Steps
Explore Props: See all available configuration options in the Props Reference.
See Examples: View more practical implementation patterns in the Examples.
Advanced Control: Learn how to control playback programmatically and handle events in Advanced Usage.