About the HTML Preview
Paste code into this online HTML preview and see it rendered next to the editor, updated as you type. Snippets, email templates and full pages with CSS and JavaScript all work, and Full Screen shows the result across the whole screen.
Use it to check an HTML email before you send it, look at a page an AI assistant wrote for you, try a layout idea without creating files, or read an .html file someone sent you. Your code runs in a sandboxed frame with its own origin. Its scripts can run, but they can't read this page, your cookies or anything toolo stores, and toolo never sends your code to a server. For Markdown files, use the Markdown Preview instead.
- Paste or type into the HTML box. To view a file, click Open File or drop an
.htmlfile onto the editor. Files up to 5 MB are accepted. - The Preview updates about 0.3 seconds after you stop typing. A fragment like
<h2>Hello</h2>is fine: the browser adds the missing<html>,<head>and<body>tags itself. - Click Full Screen to show the preview over the whole screen, so a desktop layout gets its full width. Press Esc or click Exit Full Screen to go back. The page isn't reloaded, so a form you filled in keeps its values.
- Run JavaScript is on by default. Turn it off to see the page before any script changes it, or to stop a script that loops or keeps showing alerts. Switching it reloads the preview.
- Load Example fills the editor with a small order page that uses CSS and a button script. Clear empties the editor.
Input<h1>Hello</h1>
<p>Welcome to the preview.</p>Output<html><head></head><body><h1>Hello</h1>
<p>Welcome to the preview.</p></body></html>That's the document the browser builds from two lines. Without <!DOCTYPE html> it renders in quirks mode, an old compatibility mode with slightly different layout rules, so start full pages with the doctype.
Input<!DOCTYPE html>
<p>First<p>Second <b><i>bold italic</b></i>
<table><tr><td>Cell</td></tr></table>Output<p>First</p><p>Second <b><i>bold italic</i></b>
</p><table><tbody><tr><td>Cell</td></tr></tbody></table>The parser closes the first paragraph when the second starts, fixes the order of the closing tags, ends the paragraph before the table and adds a <tbody>. The preview looks fine, so nothing tells you the source had mistakes.
Input<script>
localStorage.setItem("theme", "dark");
</script>OutputUncaught SecurityError: Failed to read the 'localStorage' property from 'Window': The document is sandboxed and lacks the 'allow-same-origin' flag.That's Chrome's message in the browser console (F12). Firefox and Safari word it differently. The sandbox gives the preview no storage, so the script stops at that line.
What the sandbox allows and blocks
The preview is an <iframe> that gets your code through its srcdoc attribute, with sandbox set to allow-scripts allow-forms allow-modals. Because allow-same-origin is left out, the browser gives the frame an opaque origin, which scripts see as null. To the browser, the preview is a separate site with no cookies and no storage.
Here's what code in the preview can and can't do:
- Scripts run, forms submit inside the frame, and
alert(),confirm()andprompt()work. - Reading
parent.documentor settingtop.locationthrows aSecurityError, so the code can't change the toolo page or send the tab somewhere else. document.cookie,localStorage,sessionStorage, IndexedDB and service workers all throw aSecurityErrortoo. Anullorigin has nowhere to keep data.window.open()returnsnull, and links withtarget="_blank"do nothing, because popups aren't allowed.- The frame can't go full screen or use the camera, microphone or location.
- Requests from
fetch()sendOrigin: null. Public APIs that allow every origin still answer. APIs that check the origin usually refuse.
What the sandbox doesn't hide
The sandbox protects the page and your data from the code. It doesn't stop the code from loading things. Images, fonts, stylesheets and scripts that the HTML points to are fetched from their own servers, and those servers see your IP address like any website would.
So with HTML you don't trust, turn off Run JavaScript before you paste it, and never type a real password into a form inside the preview. A form can still send what you type to whatever address its action names.
Why the preview can look different from your site
Most differences come from files the HTML expects to find next to it:
- Relative paths like
styles.cssorimg/logo.pngresolve against the toolo page, so they point attoolo.dev/tools/img/logo.pngand fail. Add<base href="https://your-site.com/">as the first tag in<head>, use full URLs, or paste the CSS into a<style>tag. - Media queries respond to the width of the preview frame, not your window. In split view the frame is half the width of the tool, so a responsive page often shows its mobile or tablet layout. Full Screen gives it the whole width.
- Clicking a link loads that page inside the frame, and many sites refuse to be framed and show an error. Change anything in the editor to bring your page back.
- When no CSS loads, you see the browser defaults: a white background, a serif font and an 8-pixel margin around
body. If your page looks plain, check the stylesheet links first.
How browsers repair broken HTML
Browsers never reject HTML. The WHATWG HTML Living Standard defines how the parser must handle every mistake, so Chrome, Firefox and Safari build the same document from the same broken source. That's why a page with missing closing tags still looks right, and why a preview can't tell you whether your HTML is valid.
A few repairs that surprise people:
- A
<p>can't hold block elements.<p>Intro <div>Box</div> end</p>becomes<p>Intro </p><div>Box</div> end<p></p>, so CSS aimed atp divmatches nothing. - Table rows always end up in a
<tbody>, even if you didn't write one. A selector liketable > trnever matches. - Text placed directly inside
<table>, outside a cell, moves to just before the table:<table>Note<tr><td>Cell</td></tr></table>shows Note above it. - Without
<!DOCTYPE html>, quirks mode changes some rules. For example, a<table>no longer closes an open<p>, so the table ends up inside the paragraph.
Use the same sandbox in your own app
If your app shows HTML that users write, such as email templates, widgets or AI output, render it the same way. Leave out allow-same-origin whenever you add allow-scripts. With both flags, a script in the frame can reach its own <iframe> element, remove the sandbox attribute and reload itself with full access to your page. If the HTML only has to be shown, not run, use sandbox="" and every flag stays off.
To keep the indentation readable before you paste code here, the Format mode of the HTML Minifier re-indents it, and Minify shrinks it again when you're done.
<!-- No allow-same-origin: the frame gets a null origin. -->
<iframe
title="Preview"
sandbox="allow-scripts allow-forms allow-modals"
srcdoc="<h1>Hello</h1><script>console.log(location.origin)</script>"
></iframe>function Preview({ html, runScripts }) {
return (
<iframe
// Sandbox flags apply when the frame loads, so a new key reloads it.
key={runScripts ? "scripts" : "no-scripts"}
title="Preview"
sandbox={runScripts ? "allow-scripts allow-forms allow-modals" : ""}
srcDoc={html}
style={{ width: "100%", height: 600, border: 0, background: "white" }}
/>
);
}const frame = document.createElement("iframe");
frame.title = "Preview";
frame.sandbox.add("allow-scripts", "allow-forms", "allow-modals");
frame.srcdoc = html;
// The flags are read when the frame loads, which happens on append.
document.body.append(frame);How do I preview HTML code online?
Paste the code into the HTML box and the Preview updates as you type. Click Full Screen to see the page across the whole screen, and press Esc to come back.
How do I open an HTML file on my phone?
Tap Open File and pick the file from your phone's files app. The page shows in the Preview below the editor, which is handy because phones often offer to download an .html file instead of showing it.
Why don't my CSS file and images show up?
Relative paths like css/style.css look for the file next to the toolo page, where it doesn't exist. Use full https:// URLs, add a <base href> tag with your site's address, or paste the CSS into a <style> tag.
Is it safe to preview HTML I didn't write?
The code can't read the toolo page, your cookies or stored data, because it runs in a sandbox with a null origin. It can still load files from other servers, which see your IP address, so turn off Run JavaScript for code you don't trust and don't type real passwords into its forms.
Can I preview an HTML email?
Yes. Turn off Run JavaScript, since email clients never run scripts, and you'll see how a browser draws the email. Classic Outlook for Windows renders email with Word's engine and ignores much modern CSS, so test the final version in real email clients too.
How do I see the HTML source of a website?
Press Ctrl+U in Chrome, Edge or Firefox (Cmd+Option+U on a Mac) to open the page source, then copy it into the HTML box. Add a <base href> tag with the site's address so its relative links to styles and images work.
Why does my script fail with a SecurityError?
It most likely uses localStorage, sessionStorage, cookies or IndexedDB. The sandboxed preview has no storage, so those calls throw. Wrap them in try...catch, or test that part on your own local server.