How to Use the HTML Live Preview
Get started in seconds — no installation, no sign-up, no credit card required.
Write Your Code
Type or paste any HTML into the left editor panel. Include <style> for CSS and <script> for JavaScript. The editor supports Tab key indentation and preserves your formatting.
Watch It Render
As you type, the preview pane updates automatically with a 300ms debounce. See your HTML, CSS, and JavaScript come to life instantly in a sandboxed iframe.
Test Responsive Layouts
Use the Desktop, Tablet (768px), and Mobile (375px) buttons to simulate different screen sizes. Perfect for testing CSS media queries and breakpoints.
Copy or Download
When you're happy with your code, click "Copy HTML" to grab it to your clipboard, or hit "Download" to save it as a .html file for local use.
Toggle Word Wrap
Writing long lines? Enable word wrap to keep everything visible without horizontal scrolling. Great for working with minified code or pasted snippets.
Clear and Start Fresh
Hit the "Clear" button to reset the editor to a blank slate. Perfect for starting a new experiment without closing the tab and losing your place.
Why Developers Love This Tool
Built by developers, for developers. Every feature is designed to make your workflow faster.
Instant Real-Time Preview
See your changes immediately as you type. The 300ms debounce ensures smooth performance even with large documents, and the live indicator lets you know when the preview is syncing.
Sandboxed Preview
Your code runs in a sandboxed iframe with allow-scripts allow-same-origin permissions, so localStorage, cookies and most Web APIs work just like on a real page. Because the preview shares this page's origin, its scripts can also reach the parent page and this site's storage, so only paste code you trust.
Responsive Device Simulation
Toggle between Desktop, Tablet (768px), and Mobile (375px) viewports to test CSS breakpoints. The preview constrains to exact pixel widths so your media queries fire correctly.
Export Options
Copy your HTML to the clipboard with one click, or download it as a .html file. Both methods preserve your exact formatting, including indentation and line breaks.
Developer-Friendly Editor
Tab key works for indentation (inserts 2 spaces). Monospace font. Optional word wrap. Character and line count in the status bar. Everything a code editor should have.
100% Browser-Based
No installation, no account, no server uploads. Everything runs entirely in your browser using native APIs. Your code never leaves your machine unless you choose to share it.
What You Can Build
From quick tests to full prototypes — see what's possible.
Test CSS Layouts
Try out flexbox, grid, positioning, or any CSS property. See the result instantly without touching your production codebase.
UI Component Prototyping
Design buttons, forms, cards, and navigation before committing to your framework. Test colors, spacing, and interactions.
JavaScript Debugging
Test DOM manipulation, event listeners, fetch calls, or any JavaScript code. Open browser DevTools to see console logs and inspect the preview.
Responsive Design Testing
Write mobile-first CSS and test it across viewports using the device buttons. See exactly how your breakpoints behave.
Frequently Asked Questions
Everything you need to know about using the HTML Live Preview tool.
Does this support CSS in <style> tags and JavaScript in <script> tags?
Yes! You can include any valid HTML, CSS, and JavaScript. The preview iframe renders everything just like a real browser tab. External resources (CDN links, Google Fonts, etc.) also load normally, so you can test with libraries like Bootstrap or jQuery.
Is my code saved anywhere? Can others see it?
No. Everything runs 100% locally in your browser. Your code is never sent to our servers, never stored, and never visible to anyone else. Once you close the tab, the code is gone unless you downloaded it first. This tool respects your privacy completely.
What do the Tablet and Mobile buttons actually do?
They constrain the preview iframe to fixed widths: 768px for Tablet and 375px for Mobile. This simulates smaller screens so your CSS media queries fire correctly. It's the same concept as using browser DevTools responsive mode, but built directly into the tool.
Is there a character or file size limit?
There's no enforced limit. Very large documents (hundreds of KB) may render slightly slower due to browser memory constraints, but typical HTML pages (even full frameworks) work perfectly fine. If you're pasting 10,000+ lines, consider enabling word wrap for easier reading.
Can I test JavaScript that manipulates the DOM or uses APIs?
Yes. The iframe sandbox allows allow-scripts and allow-same-origin, so document.querySelector(), event listeners, timers, and most Web APIs work as expected. Network requests (fetch, XHR) work too, though CORS restrictions still apply from the iframe context.
How is this different from CodePen, JSFiddle, or CodeSandbox?
It's intentionally simpler. CodePen and JSFiddle separate HTML, CSS, and JS into different panes — this tool gives you one unified HTML editor where you write everything together, just like a real HTML file. Great for testing full snippets without splitting your code. No account, no saving, no sharing features — just pure instant preview.
Can I use this offline?
Once the page loads, the core editor and preview functionality work offline since everything runs in the browser. However, you'll need an internet connection to access the page initially, and any external resources (CDN libraries, web fonts) won't load offline.
What browsers are supported?
All modern browsers: Chrome, Firefox, Safari, Edge, Opera. The tool uses standard Web APIs (iframe.srcdoc, Blob URLs, Clipboard API) that are universally supported. Internet Explorer is not supported.
HTML Live Preview: How the Preview Frame Behaves and How to Test With It
An HTML live preview renders your code in a separate frame a fraction of a second after you stop typing, so you can see the effect of every edit without saving a file or refreshing a tab. This one writes your markup into a sandboxed iframe, which means the preview is a real browser document with its own viewport, not a simulation.
That detail drives most of what you will want to know: why media queries respond to the device buttons, why relative image paths fail, and what to keep in mind before pasting code you did not write.
Shortcuts and editing tips
| Action | Shortcut |
|---|---|
| Indent two spaces | Tab inside the editor |
Download as preview.html | Ctrl + S |
| Copy the HTML | Ctrl + Shift + C |
| Clear the editor | Ctrl + Shift + Delete |
Ctrl + S is intercepted on purpose so the browser's "save page" dialog does not open. Nothing is stored between visits, so download anything you want to keep before closing the tab.
How the preview actually works
Each time the debounce timer fires, the editor text is assigned to the iframe's srcdoc attribute. The browser then parses it from scratch as a new document. Three consequences follow:
- Every update is a full reload. Scroll position, form input and any JavaScript state inside the preview reset. If your script runs a timer or animation, it restarts from zero on each edit.
- The frame is its own viewport. Width-based
@mediarules andvwunits measure the frame, not your whole screen. That is why the Tablet (768px) and Mobile (375px) buttons trigger real breakpoints. - The document URL is
about:srcdoc. Relative paths such asimages/logo.pngorstyle.csshave nothing to resolve against. Use absolutehttps://URLs, or inline the CSS and use data URIs for small images.
Test a responsive layout in 60 seconds
Paste this, then click Mobile and Desktop. The cards switch from one column to three at 700px.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.grid { display: grid; gap: 1rem; padding: 1rem; }
.card { background: #eef2ff; padding: 1rem; border-radius: .5rem; }
@media (min-width: 700px) {
.grid { grid-template-columns: repeat(3, 1fr); }
}
</style>
</head>
<body>
<div class="grid">
<div class="card">One</div>
<div class="card">Two</div>
<div class="card">Three</div>
</div>
</body>
</html>Tablet is 768px wide, so it shows three columns; Mobile at 375px shows one. To see the breakpoint itself, drag it: change 700px to 800px and watch Tablet flip to one column. The MDN guide to media queries covers the full syntax.
Useful experiments beyond the starter code
- Dark mode. Add
@media (prefers-color-scheme: dark) { body { background: #111; color: #eee; } }. The frame follows your operating system setting, so toggle that to test. - Accessibility checks. Remove the mouse and press Tab inside the preview. Every link and button should show a visible focus ring in a sensible order.
- Email-style HTML. Table-based layouts with inline styles render predictably here, but email clients strip far more than browsers do. Treat this as a first pass only.
What the device buttons do not test
Resizing a frame is not the same as running on a phone. The preview cannot show touch behaviour, hover-less interaction, the mobile browser's collapsing address bar (which changes what 100vh means), or device pixel ratio. Use it to confirm layout logic, then check a real device before launch. The viewport meta tag only affects real mobile browsers, so its absence will not show up in this frame.
Security: be careful with code you did not write
The frame is sandboxed, but the settings include both allow-scripts and allow-same-origin. MDN's iframe sandbox documentation warns that combining those two flags lets a framed document behave as same-origin content, which can weaken the sandbox. In plain terms: scripts you paste can run with the privileges of this page.
Do not paste code from strangers. Read any <script> block first, especially ones that call fetch, read document.cookie or reach for window.parent. Snippets from tutorials are fine; a "cool effect" sent by a stranger in a chat is not.
You can also render unsafe text deliberately. If you want a tag to display as characters rather than run, run it through the HTML encoder first.
A tidy workflow
- Draft the structure first with no CSS, and confirm the heading order and links work.
- Add styles in a single
<style>block, mobile layout first. - Switch to Tablet and Desktop and add
min-widthmedia queries only where the layout breaks. - Clean up indentation with the code beautifier, then compare revisions with the diff checker.
- Download the file. If your content began as Markdown, the Markdown to HTML converter produces the body markup to paste in.
More questions
Why are my local images and stylesheets not loading?
The preview document has no folder behind it, so relative paths like img/photo.jpg cannot be found. Link to full https:// addresses, inline your CSS, or encode small images as data URIs.
Why does my animation restart whenever I type?
Each update replaces the whole frame document, so scripts and CSS animations begin again. Pause editing for a moment and the animation will run to completion.
Can I embed another website in the preview with an iframe?
Many sites refuse it. They send an X-Frame-Options or frame-ancestors header that blocks framing, and the frame shows an error. This is a restriction set by that site, not a bug in the preview.
Why do alert and prompt dialogs work here?
The sandbox includes allow-modals, so alert(), confirm() and prompt() are permitted. Pop-ups opened with window.open are allowed too, though your browser may still ask you to approve them.
How do I share what I built?
There are no share links, since nothing is saved on a server. Download the file with Ctrl + S and send it, or paste the code into the place you want to publish it.