---
meta:
  title: "Get started with Liveblocks and Svelte"
  parentTitle: "Quickstart"
  description: "Learn how to get started with Liveblocks and Svelte"
---

Liveblocks is a realtime collaboration infrastructure for building performant
collaborative experiences. Follow the following steps to start adding
collaboration to your Svelte application using the APIs from the
[`@liveblocks/client`](/docs/api-reference/liveblocks-client) package.

<Banner title="Official package">

Liveblocks does not have a package for Svelte. If you would like to have one, or
even better if you have ideas about what kind of API you would like to use,
please let us know on
[GitHub](https://github.com/liveblocks/liveblocks/issues/1).

</Banner>

## Quickstart

<PromptCta />

<Steps>
  <Step>
    <StepTitle>Install Liveblocks</StepTitle>
    <StepContent>

      Every package should use the same version.

      ```bash trackEvent="install_liveblocks"
      npm install @liveblocks/client
      ```

    </StepContent>

  </Step>
  <Step>
    <StepTitle>Initialize the `liveblocks.config.ts` file</StepTitle>
    <StepContent>

      We can use this file later to [define types for our application](/docs/api-reference/liveblocks-client#Typing-your-data).

      ```bash
      npx create-liveblocks-app@latest --init --framework javascript
      ```

    </StepContent>

  </Step>
  <Step>
    <StepTitle>Set up the Liveblocks client</StepTitle>
    <StepContent>

      The first step in connecting to Liveblocks is creating a client which
      will be responsible for communicating with the back end.

      ```ts file="room.js"
      const client = createClient({
        publicApiKey: "{{PUBLIC_KEY}}",
      });
      ```

    </StepContent>

  </Step>

  <Step>
    <StepTitle>Join a Liveblocks room</StepTitle>
    <StepContent>

      Liveblocks uses the concept of rooms, separate virtual spaces where people collaborate.
      To create a realtime experience, multiple users must be connected to the same room.

      ```js
      const { room, leave } = client.enterRoom("my-room");
      ```

    </StepContent>

  </Step>

  <Step>
    <StepTitle>Use the Liveblocks methods</StepTitle>
    <StepContent>

      Now that we’re connected to a room, we can start using Liveblocks subscriptions.
      The first we’ll add is `others`, a subscription that provides information
      about which other users are connected to the room.

      ```js highlight="7-9"
      <script>
        import { onDestroy } from "svelte";
        import { room } from "./room.js";

        let others = room.getOthers();

        const unsubscribeOthers = room.subscribe("others", (updatedOthers) => {
          others = updatedOthers;
        });

        onDestroy(() => {
          unsubscribeOthers();
        });
      </script>

      <div>There are {others.length} other user(s) online</div>
      ```

    </StepContent>

  </Step>

  <Step lastStep>
    <StepTitle>Next: set up authentication</StepTitle>
    <StepContent>

      By default, Liveblocks is configured to work without an authentication endpoint
      where everyone automatically has access to rooms. This approach is great for
      prototyping and marketing pages where setting up your own security isn’t always
      required. If you want to limit access to a room for certain users, you’ll need
      to set up an authentication endpoint to enable permissions.

      <Button asChild className="not-markdown">
        <a href="/docs/api-reference/authentication">
          Set up authentication
        </a>
      </Button>
    </StepContent>

  </Step>
</Steps>

## What to read next

Congratulations! You now have set up the foundation to start building
collaborative experiences for your Svelte application.

- [@liveblocks/client API Reference](/docs/api-reference/liveblocks-client)

---

## Examples using Svelte

<ListGrid columns={2}>
  <ExampleCard
    example={{
      title: "Live Cursors",
      slug: "live-cursors/sveltekit-live-cursors",
      image: "/images/examples/thumbnails/live-cursors.jpg",
    }}
    technologies={["nextjs", "vuejs", "sveltekit", "solidjs", "javascript"]}
    openInNewWindow
  />
  <ExampleCard
    example={{
      title: "Live Avatar Stack",
      slug: "live-avatar-stack/sveltekit-live-avatars",
      image: "/images/examples/thumbnails/live-avatar-stack.jpg",
    }}
    technologies={["nextjs", "nuxtjs", "vuejs", "sveltekit", "solidjs"]}
    openInNewWindow
  />
</ListGrid>

---

For an overview of all available documentation, see [/llms.txt](/llms.txt).
