Concepts

Slices

Last updated

What are slices?

Slices are sections of a website page — like a block of text, a hero, or a call to action. They are modeled using a collection of fields.

Content writers build website pages using a stack of slices.

A screenshot of slices in the Page Builder.

A page built with slices. This website has slices like Hero and Company Logos.

Slices are created from scratch by developers. A slice’s fields are modeled by a developer during the content modeling process. A developer then builds a UI component to display when the slice is used in a page.

Developers control which slices are available to content writers. For example, a homepage might allow a Hero slice, while a blog post might allow a Quote slice. When needed, slices can be made available to multiple page types.

A slice’s files, including its model and component, are saved in the website’s code.

Learn more about content modeling

How to create a slice

Slices are created using the Type Builder, a tool for building by hand, or the Prismic CLI, a tool for AI agents.

Slice variations

Multiple versions of a slice can be modeled as slice variations.

For example, a “Text with Image” slice might have a variation for “Image on Left” and another for “Image on Right.”

A screenshot of an example Text With Image slice using the Image on Left variation.

Image on Left

A screenshot of an example Text With Image slice using the Image on Right variation.

Image on Right

Content writers can select a variation in the Page Builder.

A screenshot of variations in the Page
Builder.

Selecting a variation in the Page Builder.

Each variation has its own set of fields to account for content differences between variations.

How to add a slice variation

Display slices

Prismic provides components to display a page’s slices for Next.js, Nuxt, and SvelteKit.

<SliceZone
  slices={page.data.slices}
  components={{
    text: TextSlice,
    call_to_action: CallToActionSlice,
  }}
/>

See the <SliceZone> documentation to learn more.

Slice components

Each slice has a corresponding React, Vue, or Svelte component, depending on your website’s framework. A slice’s component is displayed whenever the slice is used in a page.

All slice components are exported from a generated index.ts file. The export can be passed directly to <SliceZone>’s components prop.

import { components } from "@/slices";

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

Simulate slices

You can interactively develop slice components using the Type Builder. The simulator provides a live view of your slice and a mock editor for providing the slice’s content.

A screenshot of a slice running in the Type Builder's simulator.

A slice running in the Type Builder’s simulator.

The simulator runs off a special page on your website, typically /slice-simulator.

How to simulate slices

Slice preview fails on Vercel with password protection

If slice preview works on localhost but fails when your simulator URL points to a hosted Vercel site, your deployment may be blocking follow-up asset requests.

Common symptoms include a blank simulator or errors in the browser network tab, such as 401 Unauthorized responses on /_next/static/... files.

This happens because adding only x-vercel-protection-bypass to your /slice-simulator URL authorizes the first request. Static assets loaded afterward do not include that query parameter, so Vercel applies protection again. Prismic loads /slice-simulator in an iframe, so you also need Vercel to set a bypass cookie that works in that context.

Update your slice simulator or live preview URL to include both query parameters:

  • x-vercel-protection-bypass=YOUR_TOKEN from Vercel Deployment Protection > Protection Bypass for Automation
  • x-vercel-set-bypass-cookie=samesitenone
https://your-site.com/slice-simulator?x-vercel-protection-bypass=YOUR_TOKEN&x-vercel-set-bypass-cookie=samesitenone

When not using localhost, set this URL in Prismic or in localSliceSimulatorURL in slicemachine.config.json.

Slice libraries

API Response

Here is what a slice looks like from the Content API:

{
  "id": "quote$e568fae3-e996-43c2-af06-dbf42b215cc2",
  "slice_type": "quote",
  "variation": "default",
  "version": "initial",
  "primary": {
    "quote": "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
  },
  "items": []
}

The slice’s primary content is determined by the slice’s fields.

A page’s slices are returned as an array:

{
  "id": "YCiUyRUAACQAxfZK",
  "uid": "my-first-post",
  "url": "/blog/my-first-post",
  "type": "blog_post",
  "href": "https://example-prismic-repo.cdn.prismic.io/api/v2/...",
  "tags": ["Tag 1", "Tag 2"],
  "first_publication_date": "2021-02-14T03:22:26+0000",
  "last_publication_date": "2022-07-09T00:36:18+0000",
  "slugs": ["my-first-post"],
  "linked_documents": [],
  "lang": "en-us",
  "alternate_languages": [],
  "data": {
    "title": "My first post",
    "slices": [
      {
        "id": "quote$e568fae3-e996-43c2-af06-dbf42b215cc2"
        // ...
      },
      {
        "id": "text$afba88d2-3ce4-46b5-b42b-b89e8dcd6dc5"
        // ...
      }
    ]
  }
}
Was this page helpful?