#Live preview setup
Live preview loads your frontend in a side-by-side iframe inside Studio. Editors open any entry, click Open live preview, and see exactly how their unpublished changes look on the actual site, without leaving the entry form.
Live preview does not require the Hygraph Preview SDK. You need to add the Preview widget to your models and configure a preview URL that serves DRAFT content.
#Requirements
- Permanent Auth Token with
DRAFTas the default stage - A frontend URL serving content from the
DRAFTstage
The preview refreshes when the editor saves the content entry. It does not update in real time as the editor types. Live preview is not compatible with native mobile applications. Requests made by the preview count against your project's rate limits.
#Add a preview widget
You need to configure the Preview widget once per content model.
- In your Hygraph project, click Schema.
- Select the model you want to enable preview for.
- Click the Sidebar tab at the top of the screen.
- Select the Preview widget from the right sidebar.
- Complete the Preview name and URL template fields. See Define a preview URL template for how to build the URL.
- Click Add.
If more than one preview URL is required, for example, a local development URL and a staging URL, click + Add to add additional URLs. Editors select between them using a dropdown in the content entry sidebar.
#Define a preview URL template
The URL template tells Studio how to construct the preview link for each entry. It uses your domain plus one or more field values from the content entry as identifiers.
Use curly brace notation to insert field values. As soon as you type { in the URL template field, Studio shows two groups of available tokens:
Available fields: These are the fields on your model. Default system fields available on every model are id, createdAt, updatedAt, publishedAt, and scheduledIn. Any custom fields you have added to the model, such as slug, also appear here.
Other placeholders: {locale} adds a locale selector to the preview. When your model has more than one locale configured, editors can switch between locales directly in the preview panel. Without it, the switcher does not appear even if your project has multiple locales configured.
Common patterns:
https://preview.your-domain.com/blog/{slug}https://your-domain.com/{slug}?preview=truehttps://preview.your-domain.com/posts/{id}https://preview.your-domain.com/{locale}/posts/{slug}
Use {slug} when your frontend routes by slug. Use {id} when it routes by entry ID. You can combine multiple fields and placeholders in a single template if your URL structure requires it.
If your preview URL serves the PUBLISHED stage, editors will see changes in the preview only after they publish the content entry. The preview will not show any draft content. See Configure your frontend for DRAFT content.
We recommend including a secret token in the URL that only your application and Hygraph know. This prevents the preview URL from being accessed directly without going through Studio.
https://your-domain.com/api/preview?secret=MY_SECRET_TOKEN&slug={slug}
#Add a Variants preview URL
If your model uses Variants, you can add one of the variant placeholders, such as ${variant.id}, {variant.segments[0].id}, or {variant.segments[*].id}, to your URL template. This lets Studio construct a preview URL that passes the variant or segment ID to your frontend. Editors can preview how content looks for a specific segment before publishing. Without a variant placeholder in the URL template, the variant or segment ID is not passed to the frontend and the preview shows the main entry content only.
You can combine variant placeholders with {locale} in the same URL template.
Ensure you have added the Preview widget and defined a base URL template before configuring Variants preview.
- In your Hygraph project, click Schema and select the model.
- Click the Sidebar tab.
- Click Edit widget on the Preview widget.
- Under Variant preview settings, complete the Preview name and URL template fields.
- Click Update.
Supported URL template tokens for Variants:
| Token | Resolves to |
|---|---|
${variant.id} | The variant ID |
{variant.segments[0].id} | The first segment ID |
{variant.segments[*].id} | All segment IDs, comma-separated and URL-encoded |
Example URLs and what they resolve to:
| Approach | Template | Example output |
|---|---|---|
| By variant ID | https://preview.your-domain.com/post/${id}?variant=${variant.id} | .../post/cmeaacg1t...?variant=cmeaacld1... |
| By first segment | https://preview.your-domain.com/post/${id}?segment={variant.segments[0].id} | .../post/cmeaacg1t...?segment=cmeaafql4... |
| By all segments | https://preview.your-domain.com/post/${id}?segments={variant.segments[*].id} | .../post/cmeaacg1t...?segments=cmeaafql4...%2Ccmeaafn9e... |
{variant.segments[*].id} returns all segment IDs as a comma-separated list. Commas are URL-encoded as %2C. Your frontend interprets the query parameter and queries the API for the correct variant.
#Configure your frontend for DRAFT content
Your preview URL needs to serve content from Hygraph's DRAFT stage. There are two approaches.
Two-token strategy: Create one Permanent Auth Token with DRAFT as the default stage and use it in your preview environment. Create a second token with PUBLISHED as the default stage for production. Your application switches between them based on context.
To create a preview token:
- Go to Project Settings > Access > Permanent Auth Tokens.
- Click Add token and give it a name, for example,
Preview token. - Set the default content stage to DRAFT.
- Click Initialize default permissions on the token page.
Repeat the above steps for the PUBLISHED content stage for your production token.
Draft mode strategy: Use your framework's built-in preview or draft mode mechanism. The preview URL hits a route that sets a cookie or flag, which your application reads to switch from PUBLISHED to DRAFT queries. This is the recommended approach for Next.js.
See Frontend implementation for examples on retrieving DRAFT content in Next.js, Nuxt, and Astro.
#Verify the setup
- Open an entry in Studio for the model you configured live preview.
- In the right sidebar, click Open live preview. The preview should load alongside the entry form.
- Make a change to a field and click Save & Preview. The preview should refresh and show your change.
If the preview panel is blank or shows an error, see the Troubleshooting section.
#Edit or delete a preview URL
- Navigate to the Schema builder and select the model.
- Next to the Preview widget, do one of the following:
- To edit a preview URL, click the pencil icon, and update the Preview name or URL template fields.
- To delete a preview URL, click the trash icon at the end of the row you want to remove.
- Update the Preview name or URL template fields.
- Click Update.
A preview widget needs to contain at least one URL. If you need to remove the only configured URL, delete the widget from the Sidebar tab instead. You can re-add the widget later if needed.
Delete the preview widget
Delete a preview widget
- Navigate to the Schema builder.
- Select the model that contains the preview widget that you want to delete.
- Click on the context menu for the widget, and select
Remove.
#Troubleshooting
#CSP or security header issues
Your site's security headers are blocking iframe embedding. Check your response headers:
- Navigate to the Network tab in your browser console.
- Search for the page you are trying to see.
- Under the Headers subtab, click the Response Headers.
- Determine whether the security configuration matches one of the options below:
- If
X-Frame-Optionsis set, remove it from your application. - If
Content-Security-Policyis set, addframe-ancestors 'self' https://*.hygraph.comto the header value.
- If
In case you are hosting on Vercel, go to Settings > Deployment Protection and disable Vercel Authentication. This removes the X-Frame-Options header. Disabling Vercel Authentication makes preview deployments publicly accessible.
#Stale data
Your frontend is serving the PUBLISHED stage in preview. Check that:
- Your preview token has
DRAFTset as the default content stage. - Your application is using the preview token, not the production token, when the preview URL is loaded.
- Your GraphQL queries are not hardcoding
stage: PUBLISHED. - You do not have a caching layer active in preview mode.
#No Open live preview button
The entry should have been saved at least once, that is, it should exist in the DRAFT stage. The button does not appear on unsaved entries.
#What's next
- Frontend implementation: Configure your Next.js, Nuxt, or Astro frontend to serve DRAFT content for live preview.
- Click to Edit setup: Learn how to install the Hygraph Preview SDK and configure Click to Edit so editors can jump from any preview element directly to the corresponding field in Hygraph Studio.