Render Sanity Portable Text in Next.js with Tailwind CSS v4
Render Sanity Portable Text in Next.js Server Components with @portabletext/react and Tailwind CSS v4: headings, links, custom blocks, and typography.
- sanity 6.24.0
- @portabletext/react 3.2
- Next.js 16.4.6
Sanity stores rich text as Portable Text (a JSON array of blocks and custom objects) rather than raw HTML. To render it cleanly in Next.js with Tailwind CSS v4, install @portabletext/react and pass a small components map for headings, links, images and code blocks.
1. Install @portabletext/react
npm install @portabletext/react @sanity/image-urlpnpm add @portabletext/react @sanity/image-urlyarn add @portabletext/react @sanity/image-urlbun add @portabletext/react @sanity/image-url2. Create a reusable PortableText renderer
import { PortableText, type PortableTextComponents } from "@portabletext/react";import type { TypedObject } from "@portabletext/types";import Link from "next/link"; const components: PortableTextComponents = { block: { h2: ({ children }) => ( <h2 className="mt-10 mb-3 text-2xl font-semibold tracking-tight">{children}</h2> ), h3: ({ children }) => ( <h3 className="mt-7 mb-2 text-lg font-semibold">{children}</h3> ), normal: ({ children }) => ( <p className="mb-4 leading-relaxed text-muted-foreground">{children}</p> ), blockquote: ({ children }) => ( <blockquote className="my-6 border-l-2 border-border pl-4 italic text-muted-foreground"> {children} </blockquote> ), }, marks: { link: ({ children, value }) => { const href = value?.href ?? "#"; const external = href.startsWith("http"); return external ? ( <a href={href} target="_blank" rel="noopener noreferrer" className="underline underline-offset-4"> {children} </a> ) : ( <Link href={href} className="underline underline-offset-4">{children}</Link> ); }, },}; export function RichText({ value }: { value: TypedObject[] }) { return <div className="max-w-prose"><PortableText value={value} components={components} /></div>;}Three things that trip people up
- Missing custom block types: If your schema has a custom
imageorcodeblock inside Portable Text, register it undertypes: { image: ..., code: ... }or@portabletext/reactlogs a warning and skips it. - Tailwind v4 typography plugin: If you prefer
className="prose"instead of styling each tag, install@tailwindcss/typographyand load it with@plugin "@tailwindcss/typography";in your v4 CSS file. - Unpublished edits not showing: If new rich-text paragraphs don't appear after hitting Publish, check Sanity published changes not showing on Next.js.
Questions
Can I render Portable Text inside a Next.js Server Component?
Yes. @portabletext/react has no client-side state, so it renders purely on the server with zero client JavaScript unless one of your custom types components uses "use client".
Need ready-made Sanity schemas with Portable Text?
Grab our free Sanity content models (blog posts, docs, FAQs, authors) — copy the schema or install via the shadcn CLI.
Related articles
- SanitySanity published changes not showing on your Next.js sitePublished in Sanity Studio but your live site still shows old content? Fix Next.js caching with revalidateTag webhooks, useCdn: false, dataset mismatches, and drafts.
- SanitySanity GROQ vs GraphQL: which query language to useCompare GROQ and GraphQL in Sanity: zero-deploy schema changes, inline joins, Sanity TypeGen with defineQuery, and when GraphQL still makes sense.
- Tailwind CSS v4Does Tailwind CSS v4 have a config file?Not by default: v4 is configured in CSS with @theme. Where every v3 setting went, how to load an old tailwind.config.js with @config, and when to keep it.
Still stuck? We answer every message ourselves. Write to us