Sanity CMS with Next.js or Astro: Complete Guide
For managing content on a website, WordPress is often the first choice. However, for modern projects — high-performance showcase sites, blogs, corporate sites, landing pages — headless CMS have become a credible alternative, especially when targeting performance, SEO and flexibility.
Among them, Sanity CMS has become a reference thanks to its ability to adapt to custom content, while offering a modern editing interface. Combined with Astro or Next.js, Sanity allows you to build fast, well-referenced sites designed to evolve over time.
In this guide, I'll explain how Sanity works with these frameworks, when to choose one or the other, and why this approach can be an excellent WordPress alternative for certain projects.
Table of Contents
1. What is Sanity CMS?
The basic principle
Sanity is a headless CMS: this means that the content administration interface (the backend) is completely separated from the frontend (the site displayed to visitors).
Unlike WordPress, where content and theme are linked, Sanity provides:
Structured content (API)
Content is stored as JSON data, accessible via API (REST or GraphQL)
An admin interface (Sanity Studio)
For editors, clear and customizable
Total freedom on the frontend
Next.js, Astro, Svelte, Nuxt... You choose the technology
1. Structured and custom content
Unlike WordPress where plugins sometimes force you to adapt your content structure to the theme, with Sanity, you define exactly what you need: fields, types, validations, relationships between data.
With Sanity, content is structured as types: pages, sections, articles, projects, testimonials, FAQ...
This approach allows you to build highly customized, truly scalable sites, without workarounds. The content structure is clear, controlled and independent of design.
2. A modern editing interface
Sanity Studio is fast, clear and pleasant to use. When properly configured, it allows non-technical teams to:
- •Edit texts and images
- •Manage pages and content
- •Publish or unpublish content
- •Preview changes in real time
3. A flexible API: GROQ and GraphQL
Sanity allows you to query data via two methods:
- →GROQ (Graph-Relational Object Queries): a query language specific to Sanity, very powerful and flexible
- →GraphQL: if you prefer this standard
GROQ is often preferred for its simplicity and expressive power. You retrieve exactly what you need without overloading queries.
Example GROQ query:
// GROQ query example
const query = `
*[_type == "page" && slug.current == $slug][0]{
title,
description,
content,
publishedAt
}
`;Key takeaway: Sanity offers total flexibility on content structure while remaining easy to use for editors. In many cases, the editing experience is more pleasant than a WordPress loaded with plugins.
2. Why Sanity works well with Astro or Next.js
Sanity is agnostic: it works with any frontend. But Astro and Next.js are particularly well suited because:
→They generate fast, optimized sites
Pre-generated HTML (SSG), ideal for SEO and performance
→They easily integrate with content APIs
Simple to call Sanity API and retrieve content
→They allow full control of design
No themes or plugins limiting customization
→They offer a modern developer experience
TypeScript, hot reload, preview system, structured code
Key takeaway: Sanity separates content from design. Astro or Next.js allow you to build a custom, optimized frontend while maintaining a simple and pleasant editing experience.
3. Is Sanity complex to use?
A common criticism of headless CMS is that they're "for developers" and unsuitable for non-technical teams. With Sanity, this depends entirely on how the interface is configured.
Here's what makes the difference:
✓ Well configured
- • Clear field names
- • Descriptions and instructions
- • Structured types
- • Validations (required fields, formats)
- • Intuitive navigation
→ Pleasant experience, sometimes simpler than WordPress
✗ Poorly configured
- • Technical names (camelCase)
- • No descriptions
- • Unstructured types
- • No validations
- • Messy navigation
→ Confusing, unusable for non-technical team
Example of a properly configured schema
export default {
name: 'page',
title: 'Page',
type: 'document',
fields: [
{
name: 'title',
title: 'Page Title',
type: 'string',
description: 'Main title displayed on the page',
validation: Rule => Rule.required().max(80)
},
{
name: 'slug',
title: 'URL',
type: 'slug',
description: 'Generated from the title',
options: { source: 'title' },
validation: Rule => Rule.required()
},
{
name: 'content',
title: 'Content',
type: 'array',
of: [{ type: 'block' }]
}
]
}Key takeaway: If Sanity Studio is well configured, editing is simple and intuitive. The key is to structure schemas from the start: clear field names, descriptions, and logical organization.
4. Astro vs Next.js: detailed comparison
Both work perfectly with Sanity. The choice depends on your project:
| Criteria | Astro + Sanity | Next.js + Sanity |
|---|---|---|
| Performance | Maximum (0 JS by default) | Very good (React) |
| SEO | Perfect (pure HTML) | Perfect (SSG/SSR) |
| Visual Editing | Possible (less smooth) | Native (Vercel Edit Mode) |
| Multilingual | Native i18n (Simple routing) | Native i18n (Routing + Middleware) |
| Interactivity | Targeted (islands) | Total (React SPA) |
| Complexity | Simple | Medium |
| Time-to-market | Fast (1-3 weeks) | Fast (1-3 weeks) |
| Ideal use case | Showcase site, blog, landing pages | Complex project, multilingual, app |
Astro + Sanity relevant for:
- →Agency/freelance showcase site
- →High-performance blog
- →Corporate site
- →Multiple landing pages
- →Documentation
Next.js + Sanity relevant for:
- →Complex multilingual site
- →Smooth visual editing required (Vercel Edit Mode)
- →Site with complex animations
- →E-commerce content (non-transactional)
- →Interactive documentation
Key takeaway: Astro prioritizes maximum performance and simplicity. Next.js prioritizes flexibility and advanced features. For a high-performance showcase site, Astro is often the best choice.
5. Code examples: Sanity with Astro and Next.js
Here are concrete examples to understand how Sanity integrates with each framework.
Astro + Sanity approach
STATIC GENERATIONsrc/pages/[slug].astro
---
import { sanityClient } from '../lib/sanity';
const { slug } = Astro.params;
// GROQ query to retrieve the page
const query = `*[_type == "page" && slug.current == $slug][0]{
title,
description,
content,
publishedAt
}`;
const page = await sanityClient.fetch(query, { slug });
if (!page) {
return Astro.redirect('/404');
}
---
<html lang="en">
<head>
<title>{page.title}</title>
<meta name="description" content={page.description} />
</head>
<body>
<h1>{page.title}</h1>
<div set:html={page.content} />
</body>
</html>✓ Advantages:
✓0 JavaScript client-side by default
✓Instant loading (< 0.5s)
✓Perfect SEO (complete HTML on first render)
Next.js + Sanity approach
SSG / ISRapp/[slug]/page.tsx
import { sanityClient } from '@/lib/sanity';
interface PageProps {
params: { slug: string }
}
async function getPage(slug: string) {
const query = `*[_type == "page" && slug.current == $slug][0]{
title,
description,
content,
publishedAt
}`;
return sanityClient.fetch(query, { slug });
}
export default async function Page({ params }: PageProps) {
const page = await getPage(params.slug);
if (!page) {
notFound();
}
return (
<div>
<h1>{page.title}</h1>
<div dangerouslySetInnerHTML={{ __html: page.content }} />
</div>
);
}
export async function generateStaticParams() {
const pages = await sanityClient.fetch(`*[_type == "page"]{ slug }`);
return pages.map((page: any) => ({
slug: page.slug.current,
}));
}✓ Advantages:
✓ISR: incremental regeneration on demand
✓Advanced preview mode (Draft Mode)
✓Full React ecosystem (animations, state management)
Key takeaway: Astro is more direct (pure HTML), Next.js offers more flexibility (advanced preview, ISR, client interactions).
6. Real example: Horizon Architecture
Horizon Architecture is a fictional architecture agency site I developed with Next.js + Sanity.
The goal was to demonstrate a modern, high-performance site with easy content management.
Why Next.js (and not Astro)?
The choice was made based on several technical requirements:
- →Multilingual: Site available in FR and EN with routing managed by Next.js
- →Complex animations with GSAP: Requires more control over client-side JavaScript
- →Smooth visual editing: Client can click directly on the site to edit content
- →Scalable architecture: Site can integrate a client portal in the future
Results achieved
Performance
Lighthouse 95-98
SEO
100/100 (structured HTML)
Editing
Simple and fast
Sanity content management
Projects managed via Sanity Studio:
- • Project pages (title, description, images, categories)
- • Team members
- • Testimonials
- • Services offered
7. Sanity vs WordPress: comparison table
| Criteria | Sanity + Astro/Next.js | WordPress |
|---|---|---|
| Performance | Excellent (SSG, 0 JS with Astro) | Variable (depends on plugins) |
| SEO | Perfect (pure HTML) | Good (with plugins) |
| Customization | Total (custom code) | Limited (themes) |
| Security | Robust (static frontend) | Vulnerable (plugins) |
| Maintenance | Low (no PHP updates) | High (core + plugins) |
| Scalability | Excellent (API architecture) | Medium (limited) |
| Hosting | Simple (static hosting) | Complex (PHP/MySQL) |
| Learning curve | Medium (developer required) | Low (accessible) |
| Best for | Modern, scalable, high-performance projects | Quick sites, standard blogs |
Key takeaway: Sanity is more technical but offers superior performance, security and scalability. WordPress remains relevant for standard blogs or clients wanting maximum autonomy without developer.
8. Costs and hosting
Example of economical architecture
Often free for reasonable usage (unlimited bandwidth)
Generous free plan available, paid plans for advanced needs
~10-15€/year (only real recurring cost)
Recommended hosting
- • Vercel (free offer available)
- • Cloudflare Pages (free offer available)
- • Netlify (free offer available)
Sanity CMS - Free Plan
- • Up to 20 users
- • 2 public datasets
- • Unlimited content and locales
- • Live preview included
Paid upgrade
- • Growth and Enterprise plans
- • Advanced features
- • Dedicated support if needed
Key takeaway: A Sanity + Astro site can run for free (excluding domain) for most showcase and blog projects. Very economical compared to hosted WordPress.
9. When to choose Sanity?
✓ Sanity is relevant if:
- • You want a fast, modern and scalable site
- • You value performance and SEO
- • You want full control over design
- • You're working with a developer
- • You want to avoid WordPress limitations
- • You want infrastructure that can evolve (app, features)
✗ Sanity is less relevant if:
- • You want a site in 1 click without developer
- • You want visual page builder (drag & drop)
- • You have an existing WordPress site with plugins
- • You want to manage everything yourself without technical skills
- • You want a pre-built theme
Key takeaway: Sanity is an excellent choice for custom, high-performance projects where you control the frontend. For quick sites without developer, WordPress or Webflow remain easier.
10. Frequently asked questions (FAQ)
Is Sanity CMS free?
Yes, Sanity offers a generous free plan including up to 20 users, 2 public datasets, unlimited content and locales, as well as live preview and visual editing tools. This is largely sufficient for most showcase sites, blogs and small projects. Paid plans (Growth and Enterprise) exist for advanced needs: private datasets, complex permissions, AI Assist, dedicated support, etc.
What's the difference between Sanity and WordPress?
WordPress is a monolithic CMS (backend and frontend linked). Sanity is headless: backend and frontend are separate. This allows you to use any technology for the frontend (Next.js, Astro...), optimize performance and avoid plugin limitations. However, Sanity requires more technical skills for initial setup.
Astro or Next.js with Sanity?
Astro is ideal for content-oriented sites (showcase, blog, corporate) where maximum performance is priority (0 JS client, pure HTML). Next.js is preferable for more complex projects requiring advanced multilingual, native and smooth visual editing (Vercel Edit Mode), interactive animations or application logic. For a simple high-performance showcase site, Astro is often the best choice.
How long to create a site with Sanity?
A simple site with Astro + Sanity can be delivered in 1 to 3 weeks. A more complex site (multipage, rich content) takes 3 to 4 weeks with Astro. With Next.js (for more advanced needs), expect 1 to 3 weeks depending on complexity. These timelines include CMS configuration, frontend development and content integration.
Do I need a developer to use Sanity?
Yes, for initial setup (schema configuration, frontend integration). Once the site is created and Sanity Studio is configured, the client can manage content independently. If Sanity Studio is well configured, editing is simple and intuitive. The key is good initial configuration.
Is editing complex for clients?
No, if Sanity Studio is well configured. The interface is modern, intuitive and often more pleasant than WordPress. Clients appreciate clear fields, real-time validations and previewing. The key is to structure schemas from the start: clear field names, descriptions, and logical organization make editing very simple.
What hosting for an Astro/Next.js + Sanity site?
Vercel, Cloudflare Pages and Netlify are the best options. All three offer generous free plans with automated Git deployment. Cloudflare Pages is excellent for Astro with generous bandwidth. Vercel is optimized by the Next.js team and offers the best integration. Netlify is also an excellent versatile alternative.
Can I migrate from WordPress to Sanity?
Yes, it's possible but requires restructuring: export WordPress data (XML or JSON), transform and import into Sanity, rebuild the frontend. It's a significant project requiring a developer. This migration can be valuable to improve performance, security and scalability, but should be considered carefully.
Conclusion
Sanity CMS is a modern, flexible and powerful solution for managing content on custom sites. Combined with Astro or Next.js, it allows you to build fast, well-referenced and scalable sites.
Astro + Sanity is an excellent choice for an ultra-fast showcase, blog or corporate site, with infrastructure that can remain very economical (often free excluding domain).
Next.js + Sanity is relevant when the project integrates advanced multilingual, native and smooth visual editing, complex animations or more advanced application logic.
The complexity doesn't lie so much in the tool as in the content design and architecture. The goal is to aim for a performant, structured and sustainable solution: an optimized frontend, well-organized content, and an administration designed for autonomy.
Need a high-performance site with Sanity CMS?
I'm Johan Lorck, freelance Next.js developer. I help companies and agencies build modern, scalable sites with Sanity CMS, Astro or Next.js.
Discuss your project→