ContentBox.js · Guide

Using ContentBox.js in Plain HTML

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 plain HTML page: no framework, no build step and no backend. 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

  1. Set up the folder
  2. Embed the editor
  3. Add saving and uploads
  4. Show the page to visitors
  5. Try it

Step 1

Set up the folder

Create a folder for your site. The files you need are in the ContentBox.js ZIP package, which you can download from your user area. From the package's public/ folder, copy these into your folder:

my-site/
├── contentbox/      # the editor
├── contentbuilder/  # the editor's base styles
├── runtime/         # the runtime
├── assets/          # sections, snippets, fonts, plugins
├── blank.html       # the page you edit, shown inside the editor
└── preview.html     # Page Preview

The pages must be opened from a web server, not by double-clicking the file: browsers don't load the interactive blocks from a file opened that way. No backend is needed. Any web server works: your hosting, XAMPP, MAMP, or the Live Server extension in VS Code. You can also start one in the folder, with Node.js:

cd my-site
npx serve -l 8000

Or with PHP:

cd my-site
php -S localhost:8000

The steps below use http://localhost:8000. With another server, use its address instead.

Step 2

Embed the editor

Create edit.html. ContentBox adds its own interface, so the body has only the scripts:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Edit</title>
    <link href="contentbuilder/contentbuilder.css" rel="stylesheet">
    <link href="contentbox/contentbox.css" rel="stylesheet">
</head>
<body>
    <script src="contentbox/contentbox.min.js"></script>
    <script>
        // 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>`);
    </script>
</body>
</html>

Keep 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.

Open http://localhost:8000/edit.html. 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 ContentBox.js editor in a plain HTML page after step 2, with Hello World

The editor after step 2. Click the text to edit it, add sections with + and blocks from the Blocks panel.

Step 3

Add saving and uploads

Now let's add saving and uploads. A page has three parts: the content (html), the styles used on the page (mainCss) and the styles of each section (sectionCss). We save all three.

Replace edit.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Edit</title>
    <link href="contentbuilder/contentbuilder.css" rel="stylesheet">
    <link href="contentbox/contentbox.css" rel="stylesheet">
</head>
<body>
    <div style="position: fixed; top: 0; left: 0; right: 0; height: 55px; z-index: 10;
                display: flex; align-items: center; justify-content: flex-end; gap: 8px;
                padding: 0 20px; background: #fff; border-bottom: 1px solid #eee">
        <button id="btnPreview">Preview</button>
        <button id="btnView">View page</button>
        <button id="btnSave">Save</button>
    </div>

    <script src="contentbox/contentbox.min.js"></script>
    <script>
        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.
        function upload(file) {
            return new Promise((resolve, reject) => {
                const reader = new FileReader();
                reader.onload = () => resolve({ url: reader.result });
                reader.onerror = reject;
                reader.readAsDataURL(file);
            });
        }

        // 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
        });

        // Load the saved page, or the default the first time
        const page = JSON.parse(localStorage.getItem('savedPage') || '{}');
        builder.loadHtml(page.html || DEFAULT_CONTENT);
        builder.loadStyles(page.mainCss || '', page.sectionCss || '');

        function save() {
            localStorage.setItem('savedPage', JSON.stringify({
                html: builder.html(),
                mainCss: builder.mainCss(),       // styles used on the page
                sectionCss: builder.sectionCss(), // styles of each section
            }));
        }

        document.querySelector('#btnPreview').addEventListener('click', () => builder.openPagePreview());
        document.querySelector('#btnView').addEventListener('click', () => {
            save();
            window.open('view.html', '_blank');
        });
        document.querySelector('#btnSave').addEventListener('click', () => {
            save();
            alert('Page saved!');
        });
    </script>
</body>
</html>

What's new

  • Saving: html(), mainCss() and sectionCss() return the three parts of the page. Here they are kept in the browser's localStorage, and loadHtml() and loadStyles() load them back the next time.
  • Uploads: upload is one function for all media. It must return an object with at least { url }.
  • Toolbar: topSpace leaves room at the top for it. Preview shows the page at any screen width (using preview.html), Save saves, and View page saves and opens the viewing page, which we add next.
The ContentBox.js editor in a plain HTML page, with saved page loaded back in

A saved page, with its styles, loads back into the editor the next time you open it.

Step 4

Show the page to visitors

The viewing page needs only the runtime, not the editor.

Create view.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>View</title>
    <link href="runtime/contentbox-runtime.css" rel="stylesheet">
</head>
<body>
    <!-- is-wrapper is required -->
    <div class="is-wrapper"></div>

    <script src="runtime/contentbox-runtime.min.js"></script>
    <script>
        const basePath = location.href.substring(0, location.href.lastIndexOf('/'));
        const page = JSON.parse(localStorage.getItem('savedPage') || '{}');

        // The saved styles: used on the page, and of each section
        document.head.insertAdjacentHTML('beforeend', (page.mainCss || '') + (page.sectionCss || ''));

        // Insert the saved page. createContextualFragment (instead of innerHTML)
        // lets scripts inside the page run.
        const wrapper = document.querySelector('.is-wrapper');
        wrapper.appendChild(document.createRange().createContextualFragment(page.html || '<p>No content available.</p>'));

        // Activate interactive blocks
        const runtime = new ContentBoxRuntime({
            pluginFolder: basePath + '/assets/plugins/',
        });
        runtime.init();
    </script>
</body>
</html>

Important: the viewing container must have the is-wrapper class.

Step 5

Try it

Open http://localhost:8000/edit.html, add some sections and blocks, and click Save. Click View page to see the saved page.

The viewing page showing page saved with ContentBox.js

The viewing page shows the saved page to visitors.

Going to production

  • Saving: localStorage keeps the page in one browser only. To publish it, send it to your server and save it there, all three parts. The PHP version of this guide shows how.
  • Uploads: send files to your own endpoint (your server, S3 or any storage) and return { url }.

Resources

© 2026 InnovaStudio

This site is built with Site Builder Kit