ContentBox.js · Guide
ContentBox.js is a JavaScript library for designing and building complete web pages 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 page to visitors.
ContentBox comes in two parts:
ContentBox
The editor, used on the page where pages are built.
ContentBox Runtime
Renders the saved page 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 ContentBox and the Runtime:
npm create vite@latest my-app -- --template react-ts
cd my-app
npm install
npm install @innovastudio/contentbox @innovastudio/contentbox-runtimeThe editor needs its assets (sections, snippets, icons, fonts, plugins). They are in the ContentBox.js ZIP package, which you can download from your user area. Copy these into your project's public/ folder:
public/
├── assets/ # sections, snippets, fonts, plugins
├── runtime/ # runtime files, used by blank.html and preview.html
├── blank.html # the page you edit, shown inside the editor
└── preview.html # Page PreviewStep 2
One thing first: the Vite starter styles (src/index.css) change the look of buttons and text on the page. In src/main.tsx, remove this line:
import './index.css'Now replace src/App.tsx:
import { useEffect } from 'react'
import ContentBox from '@innovastudio/contentbox'
import '@innovastudio/contentbuilder/public/contentbuilder/contentbuilder.css'
import '@innovastudio/contentbox/public/contentbox/contentbox.css'
function App() {
useEffect(() => {
// Create the editor
const builder = new ContentBox({
controlPanel: true,
iframeSrc: '/blank.html', // the page you edit
snippetUrl: '/assets/minimalist-blocks/content-plugins.js', // the blocks users can drag in
})
// Load the page to edit
builder.loadHtml(`
<div class="is-section is-box type-system-ui">
<div class="is-overlay"></div>
<div class="is-container v2 leading-14 size-18">
<div class="row">
<div class="column">
<h1>Hello World</h1>
<p>Start editing your page here.</p>
</div>
</div>
</div>
</div>`)
return () => builder.destroy()
}, [])
return null // ContentBox adds its own interface to the page
}
export default AppKeep the two stylesheets in this order: contentbuilder.css first, then contentbox.css.
The page you edit is shown inside the editor from blank.html. It already starts the runtime, so interactive blocks work while you edit.
Run it:
npm run devOpen the printed URL (usually http://localhost:5173). You have a working editor: click the text to edit it, add sections with the + button on the left, and drag in blocks from the Blocks button below it, including interactive ones like a countdown or a chart.

The editor after step 2. Click the text to edit it, add sections with + and blocks from the Blocks panel.
Step 3
Now let's add saving and uploads. Replace src/App.tsx again:
import { useEffect, useRef } from 'react'
import ContentBox from '@innovastudio/contentbox'
import '@innovastudio/contentbuilder/public/contentbuilder/contentbuilder.css'
import '@innovastudio/contentbox/public/contentbox/contentbox.css'
const DEFAULT_CONTENT = `
<div class="is-section is-box type-system-ui">
<div class="is-overlay"></div>
<div class="is-container v2 leading-14 size-18">
<div class="row">
<div class="column">
<h1>Hello World</h1>
<p>Start editing your page here.</p>
</div>
</div>
</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<ContentBox | null>(null)
useEffect(() => {
// Create the editor
const builder = new ContentBox({
controlPanel: true,
iframeSrc: '/blank.html', // the page you edit
snippetUrl: '/assets/minimalist-blocks/content-plugins.js', // the blocks users can drag in
topSpace: true, // leaves room at the top for our toolbar
upload, // handles image, video, audio and file uploads
})
builderRef.current = builder
// Load the saved page, or the default the first time
builder.loadHtml(localStorage.getItem('savedHtml') || DEFAULT_CONTENT)
builder.loadStyles(
localStorage.getItem('savedMainCss') || '',
localStorage.getItem('savedSectionCss') || ''
)
return () => {
builder.destroy()
builderRef.current = null
}
}, [])
const save = () => {
const builder = builderRef.current
if (!builder) return
localStorage.setItem('savedHtml', builder.html())
localStorage.setItem('savedMainCss', builder.mainCss()) // styles used on the page
localStorage.setItem('savedSectionCss', builder.sectionCss()) // styles of each section
}
return (
<div style={{
position: 'fixed', top: 0, left: 0, right: 0, height: 55, zIndex: 10,
display: 'flex', alignItems: 'center', justifyContent: 'flex-end', gap: 8,
padding: '0 20px', background: '#fff', borderBottom: '1px solid #eee',
}}>
<button onClick={() => builderRef.current?.openPagePreview()}>Preview</button>
<button onClick={() => { save(); window.open('/view.html', '_blank') }}>View page</button>
<button onClick={() => { save(); alert('Page saved!') }}>Save</button>
</div>
)
}
export default AppWhat's new
html() returns the content, mainCss() the styles used on the page, and sectionCss() the styles of each section. Here they are kept in localStorage. The next time, loadHtml() and loadStyles() load them back.upload is one function for all media. It must return an object with at least { url }.topSpace leaves room at the top for it. Preview shows the page at any screen width (using public/preview.html), Save saves, and View page saves and opens the viewing page, which we add next.
A saved page, with its styles, 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 ContentBoxRuntime from '@innovastudio/contentbox-runtime'
import '@innovastudio/contentbox-runtime/dist/contentbox-runtime.css'
export default function ViewPage() {
const containerRef = useRef<HTMLDivElement | null>(null)
useEffect(() => {
const container = containerRef.current
if (!container) return
// The saved page: the styles (mainCss and sectionCss) and the content
const mainCss = localStorage.getItem('savedMainCss') || ''
const sectionCss = localStorage.getItem('savedSectionCss') || ''
const html = localStorage.getItem('savedHtml') || '<p>No content available.</p>'
// Insert it. createContextualFragment (instead of innerHTML)
// lets scripts inside the content run.
container.innerHTML = ''
container.appendChild(document.createRange().createContextualFragment(mainCss + sectionCss + html))
// Activate interactive blocks
const runtime = new ContentBoxRuntime({
pluginFolder: window.location.origin + '/assets/plugins/',
})
runtime.init()
return () => runtime.destroy()
}, [])
return <div className="is-wrapper" ref={containerRef}></div> // is-wrapper is required for page styling
}Important: the viewing container must have the is-wrapper class.
pluginFolder tells the runtime where the plugins are. A plugin's files are loaded only when the page uses it.
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, add some sections and blocks, and click Save. Click View page to see the saved page.

The viewing page shows the saved page to visitors.
localStorage with a call to your backend or CMS, on both pages. Save all three parts: the content, mainCss and sectionCss.{ url }.docs/ folder (docs/README.md to get started, docs/reference.md for all options)