🔥 All-Access Pass — $199 USD (Regular $499) · Unlock all 2,836 Astro themes ➔
komal.nakrani
Get All-Access Pass ($199)
ThemesCategoriesDocsBlogTips & TricksPricingGet All-Access Pass ($199)
CMS & Integrations••By Komal Nakrani

Astro Storyblok Guide: Visual Editing and Live Preview

Astro Storyblok setup with visual editing: install @storyblok/astro, map bloks to components, enable live preview on a server build, and publish a static site.

#Astro#Storyblok#Headless CMS#Visual Editing

Astro works with Storyblok through the official @storyblok/astro integration: you register your access token and a map of Storyblok block types (“bloks”) to Astro components, fetch stories with useStoryblokApi(), and render them with StoryblokComponent. For click-to-edit visual editing with live preview, run a preview build with on-demand rendering and livePreview: true, and keep production as a fast static build.

This guide sets up an Astro Storyblok project on Astro 7 from scratch, explains how the Visual Editor connects to your site, and shows the two-environment setup most teams end up with.

Key Takeaways

  • @storyblok/astro exports a named storyblok() integration; configure it with accessToken and components.
  • Each Storyblok blok maps to one Astro component that receives a blok prop.
  • Spread storyblokEditable(blok) on each component’s root element to make it clickable in the Visual Editor.
  • Live preview needs on-demand rendering, livePreview: true and getLiveStory(Astro).
  • Build production statically with version: 'published' and rebuild from a Storyblok webhook.

How Storyblok and Astro fit together

Storyblok is a headless CMS built around components. Editors compose pages from reusable bloks (a hero, a feature grid, a testimonial) in a visual editor that shows your actual site in an iframe. Your code defines what each blok looks like; editors decide which bloks appear and in what order.

That model lines up with Astro’s component approach. Every blok becomes an .astro component, and pages are a recursive render of nested bloks. Because Astro renders on the server, none of the Storyblok SDK ships to visitors on the production site.

If you’re still choosing a CMS, the headless CMS guide compares Storyblok with Sanity, Git-based options and plain Markdown.

Step 1: Install and configure @storyblok/astro

Create a Storyblok space, then copy its preview access token from the space settings. Install the integration:

npm install @storyblok/astro

Store the token in .env:

# .env
STORYBLOK_TOKEN="your-preview-token"

Register the integration and map each blok’s technical name to a component path, relative to src/:

// astro.config.mjs
import { defineConfig } from 'astro/config';
import { storyblok } from '@storyblok/astro';
import { loadEnv } from 'vite';

const env = loadEnv(process.env.NODE_ENV ?? 'development', process.cwd(), '');

export default defineConfig({
  integrations: [
    storyblok({
      accessToken: env.STORYBLOK_TOKEN,
      apiOptions: { region: 'eu' },
      components: {
        page: 'storyblok/Page',
        hero: 'storyblok/Hero',
        feature: 'storyblok/Feature',
        grid: 'storyblok/Grid',
      },
    }),
  ],
});

Config files run before Astro loads .env into import.meta.env, which is why the example uses Vite’s loadEnv. Set region to match your space (eu, us, ap, ca or cn); a wrong region returns authentication errors that look like a bad token.

Step 2: Map bloks to Astro components

Each component receives the blok’s data as blok. Here is a page blok that renders its nested bloks, and a hero:

---
// src/storyblok/Page.astro
import { storyblokEditable } from '@storyblok/astro';
import StoryblokComponent from '@storyblok/astro/StoryblokComponent.astro';

const { blok } = Astro.props;
---
<main {...storyblokEditable(blok)}>
  {blok.body?.map((child) => <StoryblokComponent blok={child} />)}
</main>
---
// src/storyblok/Hero.astro
import { storyblokEditable } from '@storyblok/astro';

const { blok } = Astro.props;
---
<section class="hero" {...storyblokEditable(blok)}>
  <h1>{blok.headline}</h1>
  <p>{blok.subheadline}</p>
  {blok.cta_link?.cached_url && (
    <a href={`/${blok.cta_link.cached_url}`}>{blok.cta_label}</a>
  )}
</section>

StoryblokComponent looks up the component registered for blok.component and renders it, so nesting works to any depth. storyblokEditable adds the data attributes the Visual Editor uses to outline and select each blok. On a production site those attributes are harmless, but you can skip them there if you prefer clean markup.

For rich text fields, @storyblok/astro exports renderRichText, which converts the field to an HTML string:

---
// src/storyblok/Article.astro
import { storyblokEditable, renderRichText } from '@storyblok/astro';
const { blok } = Astro.props;
const html = renderRichText(blok.content);
---
<article {...storyblokEditable(blok)}>
  <h1>{blok.title}</h1>
  <div set:html={html} />
</article>

Step 3: Fetch stories and generate pages

A catch-all route lets editors create pages at any path in Storyblok without a code change:

---
// src/pages/[...slug].astro
import { useStoryblokApi } from '@storyblok/astro';
import StoryblokComponent from '@storyblok/astro/StoryblokComponent.astro';
import BaseLayout from '../layouts/BaseLayout.astro';

export async function getStaticPaths() {
  const storyblokApi = useStoryblokApi();
  const links = await storyblokApi.getAll('cdn/links', { version: 'published' });
  return links
    .filter((link) => !link.is_folder)
    .map((link) => ({
      params: { slug: link.slug === 'home' ? undefined : link.slug },
      props: { fullSlug: link.slug },
    }));
}

const { fullSlug } = Astro.props;
const storyblokApi = useStoryblokApi();
const { data } = await storyblokApi.get(`cdn/stories/${fullSlug}`, { version: 'published' });
const story = data.story;
---
<BaseLayout title={story.name}>
  <StoryblokComponent blok={story.content} />
</BaseLayout>

version: 'published' returns only published content, which is what production should show. A slug of undefined maps the home story to /. The getStaticPaths guide covers rest parameters like [...slug] in more depth.

Setting up Storyblok visual editing with live preview

The Visual Editor loads your site in an iframe and listens for changes. For edits to appear as editors type, the page must be rendered on demand so it can receive draft content, and the integration must have live preview enabled.

  1. Add an adapter (npx astro add node, or Netlify, Vercel or Cloudflare) so pages can render per request.
  2. Turn on live preview:
// astro.config.mjs (preview environment)
storyblok({
  accessToken: env.STORYBLOK_TOKEN,
  livePreview: true,
  bridge: true,
  components: { /* same map */ },
}),
  1. Render the page on demand with draft content, using getLiveStory to pick up changes the editor pushes:
---
// src/pages/[...slug].astro (preview environment)
import { useStoryblokApi, getLiveStory } from '@storyblok/astro';
import StoryblokComponent from '@storyblok/astro/StoryblokComponent.astro';

export const prerender = false;

const slug = Astro.params.slug ?? 'home';
const storyblokApi = useStoryblokApi();
const { data } = await storyblokApi.get(`cdn/stories/${slug}`, { version: 'draft' });
const liveStory = await getLiveStory(Astro);
const story = liveStory ?? data.story;
---
<StoryblokComponent blok={story.content} />
  1. In Storyblok, set the space’s preview URL to your preview deployment (or local dev server).

The Visual Editor requires the preview URL to use HTTPS. For local development, serve Astro over HTTPS with a plugin such as @vitejs/plugin-basic-ssl or a local certificate, or use a tunnel. When the editor pushes an update, the integration re-renders and fires a storyblok-live-preview-updated browser event you can listen for if a script needs to re-run.

The two-environment setup

Running one build for both editing and visitors forces a choice between instant previews and static speed. Most Astro Storyblok projects deploy the same repository twice:

Preview environment Production environment
Rendering On demand, with an adapter Static (output: 'static')
Content version draft published
livePreview true false
Token Preview token Public token (or preview token at build time only)
URL preview.example.com (protected) www.example.com
Updates Instantly, as editors type After a webhook-triggered rebuild

Drive the differences with one environment variable, for example STORYBLOK_ENV=preview, read in astro.config.mjs to switch livePreview, the adapter and the version. Protect the preview deployment with your host’s access controls so draft content isn’t public.

For production, add a Storyblok webhook on “story published” and “story unpublished” pointing at your host’s deploy hook. The environment variables guide explains how build-time and runtime values differ, and the deploy guide covers deploy hooks on each host.

Common Astro Storyblok issues

Problem Likely cause Fix
“Component not found” placeholder Blok name missing from components map Add the technical name and component path
401 from the API Wrong token or wrong region Match apiOptions.region to the space
Visual Editor shows a blank iframe Preview URL isn’t HTTPS, or the site blocks framing Serve over HTTPS; don’t send X-Frame-Options: DENY on preview
Edits don’t appear until refresh Page is prerendered, or livePreview is off Use prerender = false and getLiveStory on preview
Production shows draft content version: 'draft' in the production build Use published for production
Images are huge Raw asset URLs Append Storyblok’s image service path (e.g. /m/1200x0) to resize

Using Storyblok with an Astro theme

A theme gives you finished components; Storyblok gives editors control over which ones appear. Converting a theme means turning each section component into a blok component that reads blok instead of hard-coded props, then defining matching blok schemas in Storyblok. Komal themes are built from section components with typed props, which makes that mapping direct for themes in categories like Technology, where marketing pages are long stacks of sections. You can browse all Astro themes by site type.

Read the Storyblok Astro guide for the current SDK reference and Astro’s Storyblok CMS guide for an overview.

FAQ

Does Storyblok visual editing work with a static Astro site?

The production site can be static, but the Visual Editor’s live preview needs pages rendered on demand so they can load draft content and respond to edits. Most teams run a separate preview deployment with an adapter for editors and a static deployment for visitors.

What is a blok in Storyblok?

A blok is a reusable content block with its own schema, such as a hero, a feature list or a pricing table. Pages are made of nested bloks, and in Astro each blok type maps to one component through the components option.

Is Storyblok free for Astro projects?

Storyblok has a free plan for small projects and paid plans with more users, spaces and features. Check Storyblok’s pricing page for current limits. The @storyblok/astro package is free and open source.

Why does Storyblok show “component not found”?

The story contains a blok whose technical name isn’t in the components map in astro.config.mjs, or the component path is wrong. Add the exact technical name from the Storyblok block library and restart the dev server.

Do I need React or Vue to use Storyblok with Astro?

No. Blok components can be plain .astro components. You can still map bloks to React, Vue or Svelte components if you have the matching Astro integration installed.