Skip to content
Sanity
  • Content operations

    • Sanity Studio
    • Media Library
    • Canvas
    • Content Agent
    • Content Releases
    • Insights
    • App SDK

    Content backend

    • Content Lake
    • Live CDN
    • Compute
    • Agent Actions
    a white background with orange and black dots on it

    The only platform powering content operations

    Start building for free
    Start building for free
  • Use Cases

    • Headless CMS
    • E-commerce
    • Marketing
    • Media and publishing
    • PIM
    • LMS
    • Build your own

    Users

    • Developers
    • Content Editors
    • Product Owners
    • Business Leaders
    a man sits on a fence next to a horse

    Tecovas strengthens their customer connections

    Read the story
    Read the story
  • Build and Share

    • Sanity 101New
    • Sanity Learn
    • Frameworks
    • Templates
    • Tools and plugins
    • Schemas and snippets
    • Join our community

    Insight

    • Blog
    • Events
    • Customer stories
    • Guides
    A dark-themed collage showcasing branded merchandise including t-shirts, a cap, mug, tote bag, and socks, alongside various digital design elements and logos, prominently featuring "Sanity" branding.

    Grab your gear: The official Sanity swag store

    Read Grab your gear: The official Sanity swag store
  • Docs
  • Enterprise
  • Pricing
Sanity

  • Content operations

    • Sanity StudioHeadless CMS
    • Media LibraryCentralized asset management
    • CanvasAI-assisted, free-form writing
    • Content AgentAI for content operations
    • Content ReleasesStack and stage content updates
    • InsightsUnderstand content performance
    • App SDKRapidly build content apps

    Content backend

    • Content LakeThe content optimized database
    • Live CDNSimple, scalable, real-time
    • ComputeEvent handlers for content changes
    • Agent ActionsBuilt-in, content aware AI
  • Use Cases

    • Headless CMS
    • E-commerce
    • Marketing
    • Media and publishing
    • PIM
    • LMS
    • Build your own

    Users

    • Developers
    • Content Editors
    • Product Owners
    • Business Leaders
  • Build and Share

    • Sanity 101NewA quick series covering key areas of Sanity to get you up to speed.
    • Sanity Learn
    • Frameworks
    • Templates
    • Tools and plugins
    • Schemas and snippets
    • Join our community

    Insight

    • Blog
    • Events
    • Customer stories
    • Guides
  • Docs
  • Enterprise
  • Pricing
Get startedContact Sales
Join our community on Discord
Subscribe to our newsletter

Products

  • Sanity Studio
  • Media Library
  • Canvas
  • Content Agent
  • Content Releases
  • Insights
  • App SDK
  • Content Lake
  • Live CDN
  • Compute
  • Agent Actions
  • AI Assist
  • Use cases

Resources

  • Docs
  • Sanity 101
  • Sanity Learn
  • Tools and plugins
  • Frameworks
  • Templates
  • Schemas and snippets
  • Guides
  • Headless CMS explained
  • Resource library
  • Explainers
  • Enterprise CMS guides
  • Headless CMS Guides
  • Enhancing your CMS with AI
  • Compare Sanity
  • Glossary
  • Pricing

Company

  • Contact
  • Blog
  • Shop
  • Events
  • Careers
  • Changelog
  • Customer Stories
  • Agency Partners
  • Technology Partners

Trust and compliance

  • Privacy policy
  • Terms of service
  • Accessibility statement
  • Transparency statement
  • Security and compliance
  • Open Source Pledge

Keep in touch

© SANITY 2026

OSL, NOR (CET)

SFO, USA (PST)

Loading system status...
Change Site Theme
How-to guide

Really easy
real-time

Sanity’s Live Content API makes your content real-time by default—no cache purging, no refresh button smashing. This step-by-step guide walks you through setting up a free Sanity project with the Next.js template to see it in action.

Get startedFollow guide

Sanity features in this guide

Live Content API

Create a listener to subscribe and react to fine-grained changes within your Sanity dataset. Trigger content updates seamlessly without reloading the page.

→Live Content API

Sanity Studio

The customizable, React-based content editing dashboard configured with JavaScript. Run locally in a Vite development environment and deploy to your hosting—or ours.

→Learn more

Content Lake

All your Sanity content is stored in a Dataset in what we call the Content Lake. Schemaless cloud storage for all your content and assets.

→What is the Content Lake?

No more refresh button

If you have an existing Sanity project, you may prefer to read the Live Content API Docs for details on how to set it up in your application.

What's covered in this guide

You'll create a new free Sanity project using the Next.js template, publish new documents with Sanity Studio and explore how the Live Content API works.

Create a new project

From the command line, create a new free Sanity project using the Next.js template.

If you don't already have an account with Sanity, you'll be prompted to create one.

npm create sanity@latest -- --template sanity-io/sanity-template-nextjs-clean --coupon=real-guide

Now inside this directory, start the development server.

npm run dev

You should now have two apps running:

  • http://localhost:3000 – Your Next.js app
  • http://localhost:3333 – Your Sanity Studio

These apps are separately configured in the following directories:

├─ /nextjs-app
└─ /studio

The Sanity Studio is configured with code, edits you make to the configuration will render immediately in the development environment.

Content in Sanity Studio is written to a schemaless, cloud-hosted Dataset in what we call the Content Lake.

The Next.js app fetches content using Sanity Client with the GROQ query language.

Enter the Studio

Open http://localhost:3333 and log in to your Sanity Studio. The first tab that will open is the Presentation tool.

The Presentation tool is used to view your Next.js front end (http://localhost:3000) within an Iframe so that you can interact with your content.

💡 To see how Presentation can be used for interactive live preview of draft content, see the guide in this series on Visual Editing.

Publish a new post

Click "+ Create" from the top menu and select "Post."

The post document type currently has a few required fields. You will need to give this new document a

  • Title
  • Slug
  • Cover Image
    • and alternative text for the image

Once the Publish button is enabled, publish the post.

Open the post in Presentation

At the top of the document, you will see a box saying "Used on 2 pages" which you can open to show the locations of the current document in the front end.

Click the first location and you'll see the front end open side-by-side with the document editor. Make a change to the document and press Publish. You'll see the document update again, without a reload!

Sanity Studio in a browser window

It's really real-time!

Open your Next.js application in a separate private browser window, and keep it open while you publish another change to the blog post. You should see the on-page content update briefly, without having to press reload, rebuild the site or purge the cache.

How this works

Sanity Client

Open nextjs-app/sanity/lib/client.ts

Code showing configuration of Sanity Client

The most common way to interact with Sanity projects in JavaScript applications is with Sanity Client. One has been configured in the Next.js app for you.

Within the default configuration are settings for the Project ID and Dataset which you created at the beginning of this guide.

The other settings here in Sanity Client relate to Visual Editing.

You could use Sanity Client to fetch for content, but it would only be done once, at page load time. To go live we pass this client instance to another helper...

Sanity Live

Open nextjs-app/sanity/lib/live.ts

Code showing the defineLive helper from next-sanity

(The screenshot above has been simplified from the version in the template, to remove the token which is used for Visual Editing)

The defineLive helper from next-sanity allows you to turn a static fetch at load-time into a live-updating data source. Your Next.js app listens to published changes in your Dataset and refreshes content without the need to reload. It also handles caching.

Root layout component

Open nextjs-app/app/layout.tsx

Code highlighting a SanityLive component

The <SanityLive /> component comes from the defineLive helper and sets up the Event Source listener for content changes for the result of any fetches performed with sanityFetch.

The combination of <SanityLive /> and sanityFetch is all you need to make a Next.js application "live by default."

Next steps

Some ideas of what you might do next.

  • Commit this repository to your Git provider and deploy to Vercel to share these live previews with content creators
  • Add or edit Sanity Studio schema types. The template comes with a few already created, try adding a new field to post.ts in the /studio directory and see how the Studio updates imediately.
  • Explore GROQ, queries.ts in the /nextjs-app directory contains all the queries that the Next.js app currently makes. You can test queries in the Studio using the Vision tool.
  • Take the Day One with Sanity Studio Course to get a from-the-ground-up understanding of how to create new Sanity projects.
Go deeper

More resources

Course • Sanity Learn

Integrated Visual Editing with Next.js

The ultimate upgrade for content authors is to have absolute confidence in the impact of their work before they press publish – as well as the tools to rapidly find and update even the most minor pieces of content.

→View course

Visual Editing with Sanity

Introduction to Sanity's Visual Editing features, architecture, and where to go to learn more.

Enabling drag and drop for Visual Editing

Core concepts for enabling drag and drop functionality within the Presentation tool

Visual Editing: give content teams a GPS for your CMS

product

Visual Editing streamlines everyday content management with an intuitive, one-click path from website preview content to Studio.

Molly Friederich
Simeon Griggs

Molly Friederich and 1 other

What's next?

Visual Editing, the Presentation tool and Sanity Studio and are just a few parts of the Sanity Content Operating System. Get a fresh start on a new project or take a guided course for more.

Get startedSanity Learn

Explore more guides

Sanity TypeGen

Learn how Sanity Studio's flexible content modeling and GROQ queries can be made type-safe.

→Flexible schemas, Type-safe queries

Visual Editing

Separate content from code and let authors publish their own changes, while you focus on what you'd rather do.

→Fix a typo without a PR

Live Content API

Make all your content real-time content. Build live-by-default applications without touching the refresh button or busting the cache.

→Really easy real-time
npm create sanity@latest -- --template sanity-io/sanity-template-nextjs-clean --coupon=real-guide
├─ /nextjs-app
└─ /studio