---
title: "@prismicio/svelte - v2"
tags: ["latest"]
category: "api-references"
audience: developers
lastUpdated: "2026-01-15T00:40:43.000Z"
---

# Overview

`@prismicio/svelte` is the official Prismic package for creating [Svelte](https://svelte.dev/)-based websites.

With this package, you can:

* Display Prismic [images](https://prismic.io/docs/fields/image.md), [links](https://prismic.io/docs/fields/link.md), and [rich text](https://prismic.io/docs/fields/rich-text.md) using components.
* Display [slice zones](https://prismic.io/docs/slices.md) with custom components.
* Set up Prismic [previews](https://prismic.io/docs/preview.md) in [SvelteKit](https://svelte.dev/docs/kit/introduction) websites.

This page documents all APIs provided by `@prismicio/svelte`.

> See the [SvelteKit guide](https://prismic.io/docs/sveltekit.md) to learn how to build websites using this package.

> **Important**
>
> We only guarantee support with SvelteKit websites.

# Install

`@prismicio/svelte` is installed when [bootstrapping](https://prismic.io/docs/sveltekit.md#set-up-a-sveltekit-website) a SvelteKit project with `@slicemachine/init`.

```sh
npx @slicemachine/init@latest
```

It can also be manually installed in any Svelte project:

```sh
npm install --save @prismicio/svelte @prismicio/client
```

[`@prismicio/client`](https://prismic.io/docs/technical-reference/prismicio-client.md) is a peer dependency and must be installed.

# API

All components can be imported as named imports.

The following example imports [`PrismicImage`](#prismicimage):

```ts
import { PrismicImage } from "@prismicio/svelte";
```

## `<PrismicImage>`

Displays an optimized image from an [image field](https://prismic.io/docs/fields/image.md).

```svelte
<PrismicImage field={slice.primary.image} />
```

> See examples and tips on the [image field](https://prismic.io/docs/fields/image.md#display-images) page.

| Prop                      | Type                                    | Description                                                                                                                                                                                                                             | Default      |
| ------------------------- | --------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ |
| field                     | ImageField                              | An image field to display.                                                                                                                                                                                                              | None         |
| imgixParams (optional)    | object                                  | An object of [imgix URL parameters](https://docs.imgix.com/apis/rendering). See an [example](https://prismic.io/docs/fields/image.md#transform-images-through-the-api).                                                                 | None         |
| alt (optional)            | ""                                      | Declare an image as decorative.                                                                                                                                                                                                         | None         |
| fallbackAlt (optional)    | ""                                      | Declare an image as decorative if the image field does not have alt text.                                                                                                                                                               | None         |
| widths (optional)         | number\[] \| "thumbnails" \| "defaults" | Widths used to build a `srcset` value for the image field.- `"thumbnails"` uses the image field's thumbnails.
- `"defaults"` uses `[640, 750, 828, 1080, 1200, 1920, 2048, 3840]`.Only one of `widths` or `pixelDensities` can be used. | `"defaults"` |
| pixelDensities (optional) | number\[] \| "defaults"                 | Pixel densities used to build a `srcset` value for the image field.- `"defaults"` uses `[1, 2, 3]`.Only one of `widths` or `pixelDensities` can be used.                                                                                | None         |

## `<PrismicLink>`

Displays a link from a [link field](https://prismic.io/docs/fields/link.md) or document.

```svelte
<PrismicLink field={slice.primary.link} />
```

> See examples and tips on the [link field](https://prismic.io/docs/fields/link.md#display-links) page.

| Prop           | Type                                                       | Description                                                                                                                          | Default                                 |
| -------------- | ---------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------- |
| field          | LinkField                                                  | A link field to link. Only one of `field`, `document`, or `href` can be used.                                                        | None                                    |
| document       | PrismicDocument                                            | A Prismic document to link. Only one of `field`, `document`, or `href` can be used.                                                  | None                                    |
| href           | string                                                     | A URL to link. Only one of `field`, `document`, or `href` can be used.                                                               | None                                    |
| rel (optional) | undefined \| string \| ((metadata) => string \| undefined) | A `ref` attribute. A function can be passed to determine the value based on the link. Use `undefined` to remove the `rel` attribute. | `"noreferrer"` if the link is external. |

## `<PrismicText>`

Displays plain text from a [rich text field](https://prismic.io/docs/rich-text.md).

```svelte
<PrismicText field={slice.primary.text} />
```

| Prop                 | Type          | Description                               | Default |
| -------------------- | ------------- | ----------------------------------------- | ------- |
| field                | RichTextField | A rich text field to render.              | None    |
| fallback (optional)  | string        | Rendered if the rich text field is empty. | None    |
| separator (optional) | string        | Separator used between text blocks.       | `" "`   |

## `<PrismicRichText>`

Displays formatted text from a [rich text field](https://prismic.io/docs/rich-text.md).

```svelte
<PrismicRichText field={slice.primary.text} />
```

> See examples and tips on the [rich text field](https://prismic.io/docs/fields/rich-text.md#display-rich-text) page.

| Prop                  | Type          | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                               | Default                                                    |
| --------------------- | ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------- |
| field                 | RichTextField | A rich text field to render.                                                                                                                                                                                                                                                                                                                                                                                                                                                              | None                                                       |
| components (optional) | object        | A map of rich text block types to Svelte components or shorthand objects with HTML attributes and an optional `as` property.The available heading types are `heading1` to `heading6`. The available block types are `paragraph`, `preformatted`, `list`, `oList`, `listItem`, `oListItem`, `image`, and `embed`. The available inline types are `strong`, `em`, `hyperlink`, `label`, and `span`. See an [example](https://prismic.io/docs/fields/rich-text.md#use-custom-ui-components). | Standard HTML elements (e.g. `heading1` becomes a `<h1>`). |

## `<PrismicTable>`

Displays a table from a [table field](https://prismic.io/docs/fields/table.md).

```svelte
<PrismicTable field={slice.primary.table} />
```

> See examples and tips on the [table field](https://prismic.io/docs/fields/table.md#display-tables) page.

| Prop                  | Type       | Description                                                                                                                                                                                                                                                                                                                                                                  | Default                                                    |
| --------------------- | ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------- |
| field                 | TableField | A table field to render.                                                                                                                                                                                                                                                                                                                                                     | None                                                       |
| components (optional) | object     | A map of table elements and rich text block types to Svelte components or shorthand objects with HTML attributes.The available table elements are `table`, `thead`, `tbody`, `tr`, `th`, and `td`. The available rich text block types are `paragraph`, `em`, `strong`, and `hyperlink`. See an [example](https://prismic.io/docs/fields/table.md#use-custom-ui-components). | Standard HTML elements (e.g. `table` becomes a `<table>`). |
| fallback (optional)   | Component  | Rendered if the table field is empty.                                                                                                                                                                                                                                                                                                                                        | None                                                       |

## `<PrismicEmbed>`

Displays embedded content from an [embed field](https://prismic.io/docs/fields/embed.md).

```svelte
<PrismicEmbed field={slice.primary.embed} />
```

> See examples and tips on the [embed field](https://prismic.io/docs/fields/embed.md#display-embed-fields) page.

| Prop  | Type       | Description               | Default |
| ----- | ---------- | ------------------------- | ------- |
| field | EmbedField | An embed field to render. | None    |

## `<SliceZone>`

Renders [slices](https://prismic.io/docs/slice.md) from a slice zone.

```svelte
<SliceZone slices={page.data.slices} {components} />
```

> See examples and tips on the [slices](https://prismic.io/docs/slices.md#display-slices) page.

| Prop                        | Type                                                                    | Description                                            | Default |
| --------------------------- | ----------------------------------------------------------------------- | ------------------------------------------------------ | ------- |
| slices                      | SliceZone                                                               | A slice zone to render.                                | None    |
| components                  | Record\<string, Component\<SliceComponentProps>> (see definition below) | A map of slice types to Svelte components.             | None    |
| defaultComponent (optional) | Component                                                               | Rendered if a slice does not have a component mapping. | None    |
| context (optional)          | any                                                                     | Arbitrary data made available to all slice components. | None    |

**SliceComponentProps definition:**

| Property | Type     | Description                                        | Default |
| -------- | -------- | -------------------------------------------------- | ------- |
| slice    | Slice    | The slice object being displayed.                  | None    |
| slices   | Slice\[] | All slices in the slice zone.                      | None    |
| index    | number   | The index of the slice in the slice zone.          | None    |
| context  | unknown  | The data passed to `<SliceZone>`'s `context` prop. | None    |

## `<SliceSimulator>`

Adds support for [live slice previews](https://prismic.io/docs/sveltekit.md#live-previews-in-the-page-builder) in the Page Builder and Slice Machine.

```svelte
<SliceSimulator let:slices>
  <SliceZone {slices} {components} />
</SliceSimulator>
```

> See the [SvelteKit guide](https://prismic.io/docs/sveltekit.md#live-previews-in-the-page-builder) to learn how to set up live previews.

| Prop                  | Type    | Description                                                                      | Default     |
| --------------------- | ------- | -------------------------------------------------------------------------------- | ----------- |
| children              | Snippet | The content to render inside the simulator, typically a `<SliceZone>` component. | None        |
| zIndex (optional)     | number  | The z-index value of the simulator so that it's displayed above layout elements. | `100`       |
| background (optional) | string  | The background color of the simulator to match your website's design.            | `"#ffffff"` |

# SvelteKit API

`@prismicio/svelte` provides components and functions for [SvelteKit](https://svelte.dev/docs/kit/introduction).

All SvelteKit components and functions can be imported as named imports from `@prismicio/svelte/kit`.

The following example imports [`PrismicPreview`](#prismicpreview):

```ts
import { PrismicPreview } from "@prismicio/svelte/kit";
```

## `<PrismicPreview>`

Adds support for [content previews](https://prismic.io/docs/preview.md) by including the Prismic toolbar and event listeners. Webpages are automatically refreshed when a new content draft is saved.

```tsx
<PrismicPreview repositoryName="example-prismic-repo" />
```

> See the [SvelteKit guide](https://prismic.io/docs/sveltekit.md#set-up-previews-in-sveltekit) to learn where to use this component.

| Prop                       | Type   | Description                                                                        | Default     |
| -------------------------- | ------ | ---------------------------------------------------------------------------------- | ----------- |
| repositoryName             | string | The Prismic repository name.                                                       | None        |
| routePrefix (optional)     | string | The route parameter prefixed during preview sessions.                              | `"preview"` |
| routePrefixName (optional) | string | The name of the preview-specific route parameter prefixed during preview sessions. | `"preview"` |

## `enableAutoPreviews()`

Configures a Prismic client to automatically fetch draft content during a preview session.

```ts
enableAutoPreviews({ client, cookies });
```

> Projects [bootstrapped](https://prismic.io/docs/sveltekit.md#install-prismic-and-slice-machine) with `@slicemachine/init` use this function in the generated `prismicio.ts`.

| Parameter | Type    | Description                                                                                                | Default |
| --------- | ------- | ---------------------------------------------------------------------------------------------------------- | ------- |
| client    | Client  | A Prismic client.                                                                                          | None    |
| cookies   | Cookies | The `cookies` object provided to a route's `load()` function. This parameter is required to load previews. | None    |

## `redirectToPreviewURL()`

Redirects a content writer to a previewed document's URL. This function should only be called in a `+server` file.

```ts
redirectToPreviewURL({ client, request, cookies });
```

> Projects [bootstrapped](https://prismic.io/docs/sveltekit.md#install-prismic-and-slice-machine) with `@slicemachine/init` use this function in the generated `/api/preview` API Route.

| Parameter              | Type    | Description                                                                                  | Default     |
| ---------------------- | ------- | -------------------------------------------------------------------------------------------- | ----------- |
| client                 | Client  | A Prismic client.                                                                            | None        |
| request                | Request | The `request` object from a [`+server.ts`](https://svelte.dev/docs/kit/routing#server) file. | None        |
| cookies                | Cookies | The `cookies` object from a [`+server.ts`](https://svelte.dev/docs/kit/routing#server) file. | None        |
| defaultURL (optional)  | string  | The default redirect URL if a URL cannot be determined for the previewed document.           | `/`         |
| routePrefix (optional) | string  | The route parameter prefixed during preview sessions..                                       | `"preview"` |

# Upgrade from v1

Follow these steps to upgrade an existing project to `@prismicio/svelte` v2.

1. **Upgrade to Svelte 5**

   `@prismicio/svelte` v2 requires Svelte 5. If you are using Svelte 4 or earlier, follow the official [Svelte 5 migration guide](https://svelte.dev/docs/svelte/v5-migration-guide).

2. **Install `@prismicio/svelte` v2**

   ```sh
   npm install @prismicio/svelte@^2
   ```

3. **Replace `SvelteRichTextSerializer` with `RichTextComponents`**

   > **Important**
   >
   > This step is only necessary when using the `SvelteRichTextSerializer` TypeScript type.

   The `SvelteRichTextSerializer` TypeScript type is deprecated to phase out the "serializer" term.

   The type has been renamed to `RichTextComponents`.

   ```ts
   import type {
     SvelteRichTextSerializer, // [!code --]
     RichTextComponents, // [!code ++]
   } from "@prismicio/svelte";

   // prettier-ignore
   const serializer: SvelteRichTextSerializer = // [!code --]
   const serializer: RichTextComponents = // [!code ++]
     {
       paragraph: Paragraph
     };
   ```
