Docs › Saving and output
E-mail HTML
getHTML({ inlineStyles: true }) writes styles into style attributes.
Mail apps drop most <style> blocks and stylesheets. If you write newsletters or notices in the editor, read them with getHTML({ inlineStyles: true }): the fonts, sizes, colors and spacing you see in the editor are written into each tag's style attribute.
Try it
October news
Hello. Here is what changed this month.
- Signing up takes fewer steps.
- Writing on phones is faster.
Questions? Just reply to this mail.
Code for this demo
createEditor('#editor', {
toolbar: 'heading | bold italic | color | bulletList | link',
contentStyle: 'font-family: Georgia, serif; font-size: 16px; line-height: 1.7;',
onReady: (ed) => {
const out = document.createElement('pre');
out.style.cssText = 'white-space: pre-wrap; font-size: 12px; max-height: 220px; overflow: auto';
const btn = document.createElement('button');
btn.type = 'button';
btn.textContent = 'Show e-mail HTML';
btn.onclick = () => { out.textContent = ed.getHTML({ inlineStyles: true }); };
ed.statusEl.prepend(btn);
ed.root.after(out);
},
});Compare the saved HTML (button below) with the e-mail HTML (button under the editor).
How it works
- The HTML is laid out once off screen at the editor's width, and the computed styles are read.
- Inherited values (font, size, weight, color, line height, alignment) are written only where they differ from the parent.
- Non-inherited values (background, margin, padding, borders, radius) are written only where they differ from the bare tag.
- Everything is wrapped in
<div style="font-family: …; font-size: …; line-height: …; color: …">. - Looks from
contentStyleand fromstylesmenu classes come through as computed values.
const html = editor.getHTML({ inlineStyles: true });
await fetch('/newsletter', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ subject, html }),
});Options
| Name | Type | Default | Description |
|---|---|---|---|
getHTML({ inlineStyles }) | boolean | false | true: HTML with styles written into style attributes |
contentStyle | string | - | CSS for the editing area; computed into the e-mail HTML too |