
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeWhile Sanity doesn't have specific documentation about adding HTML directly to documents via client.create(), the recommended approach is to convert HTML to Portable Text format first using the @sanity/block-tools package.
When you need to add HTML content to a Sanity document, you should:
npm install @sanity/block-tools jsdomhtmlToBlocks():const {htmlToBlocks} = require('@sanity/block-tools')
const {JSDOM} = require('jsdom')
const html = '<p>Your HTML content here</p>'
const blocks = htmlToBlocks(html, blockContentType, {
parseHtml: (html) => new JSDOM(html).window.document
})const doc = {
_type: 'yourDocumentType',
title: 'Document Title',
body: blocks // Your converted Portable Text
}
client.create(doc).then((res) => {
console.log(`Document created with ID: ${res._id}`)
})Sanity uses Portable Text as its structured content format rather than raw HTML. This provides several benefits:
The client.create() method expects a plain JavaScript object representing the document. It must contain a _type attribute and may optionally contain an _id. For rich text content fields, that content should be in Portable Text format rather than raw HTML.
const doc = {
_type: 'bike',
name: 'Sanity Tandem Extraordinaire',
seats: 2,
}
client.create(doc).then((res) => {
console.log(`Bike was created, document ID is ${res._id}`)
})Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store