How to use Rich Text from Sanity: Abstract Syntax Tree and Renderer

5 replies
Last updated: May 18, 2022
could you help me figure out how to use rich text from sanity?

Can I not query data from the field as HTML?

I can only see stuff like:

"content": [
    "children": [
        "text": Some bold text
        "text": some normal text.
If I make some text bold, it becomes a child.

What am I missing?

May 18, 2022, 12:11 PM
May 18, 2022, 12:17 PM
The rich text data doesn’t yield HTML, it yields an AST (Abstract Syntax Tree) so it can eventually be rendered in any sort of format (HTML, JSX, etc.).
May 18, 2022, 12:23 PM
So you need a renderer. If you use React, then you should use the library you just linked. If you want HTML, you want .
May 18, 2022, 12:23 PM
There is a list of renderers here:
May 18, 2022, 12:23 PM
Thank you!
May 18, 2022, 12:34 PM

Sanity– build remarkable experiences at scale

The Sanity Composable Content Cloud is the headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?

Categorized in