ContentBuilder.js · Guide
ContentBuilder.js is a JavaScript library for creating elegant, editorial-style web content with simple drag and drop. In this guide we add it to a React app built with Vite. First we embed the editor, then we add saving, uploads and a page that shows the saved content to visitors.
ContentBuilder comes in two parts:
ContentBuilder
The editor, used on the page where content is created.
ContentBuilder Runtime
Renders the saved content on your site. It makes interactive blocks (sliders, counters, charts, accordions and more) work, both while editing and when viewing.
In this guide
Step 1
Create a React project and install ContentBuilder and the Runtime:
npm create vite@latest my-app -- --template react-ts
cd my-app
npm install
npm install @innovastudio/contentbuilder @innovastudio/contentbuilder-runtimeThe editor needs its assets (snippets, icons, fonts, plugins). They are in the ContentBuilder.js ZIP package, which you can download from your user area. Copy these into your project's public/ folder:
public/
├── assets/ # snippets, fonts, plugins
├── runtime/ # runtime files, used by the Live Preview page
└── preview.html # Live Preview pageStep 2
One thing first: the Vite starter styles (src/index.css) center all text and change heading sizes, which would change how your content looks. In src/main.tsx, remove this line:
import './index.css'Now replace src/App.tsx:
import { useEffect } from 'react'
// Editor
import ContentBuilder from '@innovastudio/contentbuilder'
import '@innovastudio/contentbuilder/public/contentbuilder/contentbuilder.css'
// Runtime
import ContentBuilderRuntime from '@innovastudio/contentbuilder-runtime'
import '@innovastudio/contentbuilder-runtime/dist/contentbuilder-runtime.css'
function App() {
useEffect(() => {
// Create the editor on the .container element
const builder = new ContentBuilder({
container: '.container',
})
// Load the blocks users can drag in
builder.loadSnippets('/assets/minimalist-blocks/content-plugins.js')
// Load the content to edit
builder.loadHtml(`
<div class="row">
<div class="column">
<h1>Hello World</h1>
<p>Start editing your content here.</p>
</div>
</div>`)
// Start the runtime, so interactive blocks work while editing
const runtime = new ContentBuilderRuntime({
pluginFolder: window.location.origin + '/assets/plugins/',
})
runtime.init()
// Make the runtime available to the editor
;(window as Window & { builderRuntime?: ContentBuilderRuntime }).builderRuntime = runtime
return () => {
builder.destroy()
runtime.destroy()
delete (window as Window & { builderRuntime?: ContentBuilderRuntime }).builderRuntime
}
}, [])
return <div className="container" style={{ maxWidth: '840px', margin: '140px auto', padding: '0 20px' }}></div>
}
export default AppThe runtime makes interactive blocks (sliders, counters, charts, accordions and more) work while you edit. pluginFolder tells it where the plugins are. A plugin's files are loaded only when the content uses it.
Run it:
npm run devOpen the printed URL (usually http://localhost:5173). You have a working editor: click the text to edit it, and drag blocks in from the panel on the right, including interactive ones like a countdown or a chart.

The editor after step 2. Click the text to edit it, and drag blocks in from the panel.
Step 3
Now let's add saving and uploads. Replace src/App.tsx again:
import { useEffect, useRef } from 'react'
// Editor
import ContentBuilder from '@innovastudio/contentbuilder'
import '@innovastudio/contentbuilder/public/contentbuilder/contentbuilder.css'
// Runtime
import ContentBuilderRuntime from '@innovastudio/contentbuilder-runtime'
import '@innovastudio/contentbuilder-runtime/dist/contentbuilder-runtime.css'
const DEFAULT_CONTENT = `
<div class="row">
<div class="column">
<h1>Hello World</h1>
<p>Start editing your content here.</p>
</div>
</div>`
// Upload handler: send the file to your server and return { url }.
// Without a server, the file can be embedded as a data URL, as here.
async function upload(file: File) {
// With a server:
// const formData = new FormData()
// formData.append('file', file)
// const response = await fetch('/api/upload', { method: 'POST', body: formData })
// return response.json() // must return { url }
const url = await new Promise<string | ArrayBuffer | null>((resolve, reject) => {
const reader = new FileReader()
reader.onload = () => resolve(reader.result)
reader.onerror = reject
reader.readAsDataURL(file)
})
return { url }
}
function App() {
const builderRef = useRef<ContentBuilder | null>(null)
useEffect(() => {
// Create the editor
const builder = new ContentBuilder({
container: '.container',
previewURL: 'preview.html', // enables the Live Preview button
upload, // handles image, video, audio and file uploads
})
builderRef.current = builder
// Load the blocks users can drag in
builder.loadSnippets('/assets/minimalist-blocks/content-plugins.js')
// Load saved content, or the default the first time
builder.loadHtml(localStorage.getItem('savedContent') || DEFAULT_CONTENT)
// Start the runtime, so interactive blocks work while editing
const runtime = new ContentBuilderRuntime({
pluginFolder: window.location.origin + '/assets/plugins/',
})
runtime.init()
// Make the runtime available to the editor
;(window as Window & { builderRuntime?: ContentBuilderRuntime }).builderRuntime = runtime
return () => {
builder.destroy()
builderRef.current = null
runtime.destroy()
delete (window as Window & { builderRuntime?: ContentBuilderRuntime }).builderRuntime
}
}, [])
const save = () => {
if (!builderRef.current) return
localStorage.setItem('savedContent', builderRef.current.html())
}
return (
<>
<div className="container" style={{ maxWidth: '840px', margin: '140px auto', padding: '0 20px' }}></div>
<div style={{ position: 'fixed', top: 20, right: 20, display: 'flex', gap: 8 }}>
<button onClick={() => builderRef.current?.viewHtml()}>HTML</button>
<button onClick={() => { save(); window.open('/view.html', '_blank') }}>Preview</button>
<button onClick={() => { save(); alert('Content saved!') }}>Save</button>
</div>
</>
)
}
export default AppWhat's new
html() returns the edited content. Here it is kept in localStorage, and loadHtml() loads it back the next time.upload is one function for all media. It must return an object with at least { url }.previewURL adds a preview button to the editor, which uses public/preview.html.
Saved content loads back into the editor the next time you open it.
Step 4
The viewing page needs only the runtime, not the editor.
Create view.html next to index.html:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>View</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/view.tsx"></script>
</body>
</html>Create src/view.tsx:
import { createRoot } from 'react-dom/client'
import ViewPage from './ViewPage'
createRoot(document.getElementById('root')!).render(<ViewPage />)Create src/ViewPage.tsx:
import { useEffect, useRef } from 'react'
import ContentBuilderRuntime from '@innovastudio/contentbuilder-runtime'
import '@innovastudio/contentbuilder-runtime/dist/contentbuilder-runtime.css'
export default function ViewPage() {
const containerRef = useRef<HTMLDivElement | null>(null)
useEffect(() => {
const container = containerRef.current
if (!container) return
// Insert the saved content. createContextualFragment (instead of innerHTML)
// lets scripts inside the content run.
const savedHtml = localStorage.getItem('savedContent') || '<p>No content available.</p>'
container.innerHTML = ''
container.appendChild(document.createRange().createContextualFragment(savedHtml))
// Activate interactive blocks
const runtime = new ContentBuilderRuntime({
pluginFolder: window.location.origin + '/assets/plugins/',
})
runtime.init()
return () => runtime.destroy()
}, [])
return (
<div
className="is-container" // required for content styling
ref={containerRef}
style={{ maxWidth: '840px', margin: '80px auto', padding: '0 20px' }}
></div>
)
}Important: the viewing container must have the is-container class.
This viewing page puts the content in the page in the browser. For SEO, render the content on the server instead, so search engines receive it in the HTML. See the Next.js version of this guide for an example.
Finally, tell Vite to build both pages. Replace vite.config.ts:
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
export default defineConfig({
plugins: [react()],
build: {
rollupOptions: {
input: {
main: 'index.html',
view: 'view.html',
},
},
},
})Step 5
With npm run dev running, drag in some blocks and click Save. Click Preview to see the saved content on the viewing page.

The viewing page shows the saved content to visitors.
localStorage with a call to your backend or CMS, on both pages.{ url }.