Skip to content

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.

Updated 3 December 2026Tested with
  • 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-url

2. Create a reusable PortableText renderer

src/components/RichText.tsxTSX
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 image or code block inside Portable Text, register it under types: { image: ..., code: ... } or @portabletext/react logs a warning and skips it.
  • Tailwind v4 typography plugin: If you prefer className="prose" instead of styling each tag, install @tailwindcss/typography and 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.

Was this page helpful?

Still stuck? We answer every message ourselves. Write to us

Building with shadcn/ui and Tailwind CSS v4?

Install 188 free blocks and components with the shadcn CLI (no account), preview them in your own brand in Studio, or get all 1,570 blocks and every theme in UI Pro (€199 once).

Use it with

This page is built from UI Pro parts: the docs article block (docs-quernly) with the code, terminal, install command, steps, contents and feedback components, included in UI Pro.