Skip to main content
Version: 1.0.0

Export HTML

Render the current design as production-ready HTML. Use it for sending emails, publishing web pages, or displaying popups.

import { useRef } from "react";
import { DragbleEditor, DragbleEditorRef } from "dragble-react-editor";

function EmailEditor() {
const editorRef = useRef<DragbleEditorRef>(null);

const handleExportHtml = async () => {
const html = await editorRef.current?.editor?.exportHtml();
// Send to your email API
await fetch("/api/emails/send", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ html, to: "user@example.com" }),
});
};

return (
<>
<DragbleEditor
ref={editorRef}
editorKey="db_your_key"
editorMode="email"
/>
<button onClick={handleExportHtml}>Send Email</button>
</>
);
}

:::info One-way export HTML is a one-way export. You cannot load HTML back into the editor. Always persist the design JSON for round-trip editing. :::

Export options

Pass options to exportHtml() to control the output:

const html = await editor.exportHtml({
title: "My Landing Page", // Sets <title> tag (web/popup mode only, ignored in email)
minify: true, // Minified output (plan-gated)
});
OptionTypeDefaultDescription
titlestringundefinedPage <title> for web and popup mode. Ignored in email mode.
minifybooleanfalseRequest minified HTML (plan-gated feature).

Export plain text

For email campaigns, you need a plain-text fallback. exportPlainText() strips all HTML and returns the text content:

const handleSendEmail = async () => {
const editor = editorRef.current?.editor;
const [html, plainText] = await Promise.all([
editor?.exportHtml(),
editor?.exportPlainText(),
]);

await fetch("/api/emails/send", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ html, plainText, to: "user@example.com" }),
});
};

Download HTML as a file

Trigger a browser download of the exported HTML:

const handleDownload = async () => {
const html = await editorRef.current?.editor?.exportHtml();
if (!html) return;

const blob = new Blob([html], { type: "text/html" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = "email-template.html";
a.click();
URL.revokeObjectURL(url);
};

Method reference

MethodReturnsDescription
exportHtml(options?)Promise<string>Export the design as a complete HTML document string
exportPlainText()Promise<string>Export the design as plain text (no HTML tags)

Next steps