• Cheat sheets
  • Documentation
  • API reference
  • Product updates
  • Sign in
Kontent.ai Learn
  • Try Kontent.ai
  • Plan
  • Set up
  • Model
  • Develop
  • Create
Copyright © 2025 Kontent.ai. All rights reserved.
  • Web
  • Privacy policy
  • Cookies policy
  • Consent settings
  • Security
  • GDPR
  • Overview
  • Manage API keys
  • Hello World
  • Hello Web Spotlight
  • Try sample apps
  • Build apps
    • Generate models
    • Resolve rich text
    • Resolve linked content
  • Decide navigation and URLs
  • Environments
  • Get Developer Certification

Resolve rich text content

Martina Farkasova, Jan Cerman
27 minutes
Download PDF
  • TypeScript
  • .NET
  • Java
  • PHP
  • Ruby
0% complete
Your content creators can put all sorts of content in rich text elements. This is where most of your longer-form content lives, and it must be displayed correctly. Learn how to resolve Kontent.ai-specific entities, such as content items and components in rich text, so that your content always looks as intended.

What can go in the rich text?

When working in the Kontent.ai rich text editor, your content creators need the freedom to add various types of content. This spans native options such as formatted text structured with headings, lists, and tables to custom content specific to your project. For example, content such as disclaimers, tweets, or videos is something you define yourself. To add these kinds of custom content, content creators can insert either new components or existing content items within the rich text element. Then, based on the content types of the components or content items, your app can decide how to display them. The same goes for linking to other content items within the rich text element. Your app needs to decide how to resolve each link. For example, you might want to use specific routing logic for different types of content items. The video below shows how to resolve rich text as explained above using a TypeScript-based Next.js web app.

Resolve inserted content items and components

Resolve content item links

Sign in with your Kontent.ai credentials or sign up for free to unlock the full lesson, track your progress, and access exclusive expert insights and tips!
Sign in
When you retrieve content items using Delivery API, the rich text element values are stored as HTML5 fragments. To display rich text in the way you want, you convert the values to portable text using @kontent-ai/rich-text-resolver. Portable text serializes your rich text content into structured blocks. For each portable text block, you can specify what to do with them and how to render them. This is useful for Kontent.ai-specific things such as content items and links to content items. But you can also specify how to resolve the more native parts of rich text such as headings, paragraphs, tables, and more. The following code shows the building blocks of rich text resolution with React components.
Structure-wise, content items and components are the same. You can create a component and a content item based on the same content type. The difference is in their scope.Components are always included in the API response because they’re an integral part of the rich text. However, if the rich text contains or links to any content items, these content items might not always be part of the API response.
Use the same approach for all types of content you want to support in your rich text elements.
Links in rich text come in many flavors. Content creators can create links to assets, content items, telephone numbers, emails, and web URLs. For content item links, you need to define routing logic based on the content item’s content type.Here’s an example of how you can resolve links that point to content items for products.
Use the same approach for links to other types of content items.
Expect the unexpectedRich text elements can be limited to contain content based on specific content types. As a result, if content creators insert or link to content items based on the wrong type, they get validation errors. This prevents them from publishing invalid content. However, they can still create invalid content while crafting their drafts. Make sure your app can safely deal with unknowns such as unexpected types of content. While published content is guaranteed to be valid, the latest content is not.

Rich text resolution in a nutshell

No code sample for this language yet. Try selecting another language at the top.
No code sample for this language yet. Try selecting another language at the top.
No code sample for this language yet. Try selecting another language at the top.
  • What can go in the rich text?
  • Rich text resolution in a nutshell
  • Resolve inserted content items and components
  • Resolve content item links
Video uses outdated importsThe rich-text-resolver package is now a monorepo with separate scoped packages. Use the following imports instead: import { PortableText } from "@kontent-ai/rich-text-resolver-react" import { transformToPortableText } from "@kontent-ai/rich-text-resolver" For React component resolvers, use: import { PortableText, PortableTextReactResolvers } from "@kontent-ai/rich-text-resolver-react"
Worked exampleCheck out an example of resolving images, headings, and tables in our sample Next.js app.