How to Preview HTML Code Safely Without Setting Up a Web Server

Learn how to open and render HTML files or snippets safely, why sandboxed previews matter, and how to check a page at phone and tablet widths.

Updated September 29, 2026 7 min read

Use the free HTML ViewerPaste or open HTML code and see the rendered web page live, safely

You receive an .html attachment from a supplier, a colleague pastes a block of markup into a chat, or a CMS exports a page you want to check before publishing. You just want to see what it looks like. Double-clicking the file usually works, but it is not always safe, relative links and images often break, and you cannot easily see how it behaves on a phone.

This guide explains what happens when a browser renders HTML, why a sandboxed preview is the safer way to look at code you did not write, and how to preview HTML in a browser tab, in your editor or from the command line. You will also learn how to diagnose the most common "it looks broken" problems.

What a browser does with an HTML file

HTML is plain text. A browser reads it from top to bottom and builds a tree of elements called the DOM. Along the way it:

  • Fetches linked resources such as stylesheets (<link rel="stylesheet">), images, fonts and scripts, resolving each path relative to the document's location.
  • Applies CSS from <style> blocks, linked files and style attributes.
  • Runs JavaScript in <script> tags, which can change the page, open pop-ups, read cookies for the page's origin or make network requests.

That last point is the reason to be careful. An HTML file opened directly from your disk runs with the permissions the browser grants to local files. Modern browsers restrict this heavily, but a page can still show convincing fake login forms or redirect you elsewhere. HTML attachments are a well-known phishing technique for exactly this reason.

What a sandboxed preview changes

An <iframe> with the sandbox attribute gives the code inside it a unique, opaque origin. Scripts can run if the sandbox allows them, but they cannot read the parent page, its cookies or its storage. A minimal example looks like this:

<iframe sandbox="allow-scripts" srcdoc="<p>Hello from the sandbox</p>"></iframe>

This is how online viewers, including ours, render untrusted markup: the code runs, you see the result, and it stays isolated from everything else in your browser.

Preview HTML with the HTML Viewer

Our HTML Viewer renders your markup live inside a sandboxed frame. Nothing is uploaded; the rendering happens in your own browser tab.

  1. Open the HTML Viewer. A sample page is loaded so you can see how it works.
  2. Paste your markup into the HTML code box, or click Open .html file to load a file from your device (up to 5 MB). You can paste a full document with <!DOCTYPE html> or just a fragment such as a single <table>.
  3. Watch the Live preview update as you type. Press Re-run if you want to restart any scripts from scratch.
  4. Use the device buttons above the preview to switch between Full width, Tablet (768px) and Phone (375px). This is the quickest way to see whether a layout collapses sensibly on small screens.
  5. Check the Console panel under the preview. Any console.log output, warnings and uncaught errors (with line numbers) appear there, which helps you spot broken scripts.
  6. Use Expand preview for a larger view, Open in new tab to see the page on its own, or Download to save the current code as page.html.

The Copy button next to the editor copies your code, and Clear empties the box when you want to start again.

Other ways to view HTML

A dedicated viewer is not the only option. Each of the alternatives below is better in some situations.

Double-click the file

Every desktop browser can open a local .html file. This is perfectly fine for pages you wrote yourself and gives you the full browser, including developer tools. The downsides are the security point above and the file:// protocol: some features (ES module imports, fetch() of local JSON, certain fonts) are blocked for local files, so pages that work on a server may fail here.

View the source of a live page

If the HTML is already on a website, press Ctrl+U (Windows and Linux) or Option+Cmd+U (Safari with the Develop menu enabled, or Chrome on Mac) to view the source, or open developer tools with F12 to inspect the live DOM. This shows what the server sent and what scripts changed afterwards, which a copy-and-paste preview cannot reproduce.

Use your code editor's preview

Editors such as VS Code have "live server" style extensions that serve a folder over http://localhost and reload on save. This is the best option when you are building a multi-file site, because relative paths to CSS, images and scripts resolve exactly as they will in production.

Serve a folder from the command line

If you have Python installed, you can serve the current folder with one command:

python -m http.server 8000

Then open http://localhost:8000 in your browser. Node users can do the same with a small static server package. This avoids file:// restrictions without installing a full editor setup.

Method Best for Limitations
Online sandboxed viewer Snippets and files from others, quick mobile-width checks Relative links to your local files will not resolve
Double-clicking the file Your own simple pages file:// restrictions, less isolation
View source / dev tools Pages already online Read-only view of someone else's site
Editor preview or local server Multi-file projects Needs setup

Why your preview looks broken

Images and styles are missing

The most common cause is relative paths. <img src="images/logo.png"> only works if images/logo.png exists next to the HTML file. A pasted snippet has no folder, so those files cannot load. Use absolute URLs (https://…) for testing, or embed a small image as a data URI with Image to Base64.

The layout is fine on desktop but tiny on a phone

Check for the viewport meta tag in the <head>:

<meta name="viewport" content="width=device-width, initial-scale=1">

Without it, mobile browsers render the page at a desktop width and shrink it. For a wider check across several real device sizes, load the published page in the Responsive Design Tester.

Characters look garbled

If you see sequences like é instead of é, the file's encoding and the declared encoding disagree. Save the file as UTF-8 and make sure <meta charset="utf-8"> is the first element inside <head>.

Scripts do nothing

Open the console. A single syntax error stops the whole script block. Also remember that sandboxed previews block access to the parent page and to cookies, so code that relies on login state or local storage from another site will behave differently.

The code is unreadable

Minified or machine-generated HTML is hard to follow. Run it through the HTML Formatter first to indent it, then preview it. If you want to experiment with separate CSS and JavaScript, move to the HTML CSS JS Editor, which has a tab for each.

Tips for reviewing HTML you did not write

  • Look before you click. Search the code for <form, action= and <script to see what it sends where.
  • Check link targets. Hovering in a preview shows the real URL; the visible text of a link can say anything.
  • Strip it down. If you only need the text, a converter such as HTML to Markdown gives you readable content without running any code.

Frequently asked questions

Is it safe to open an HTML file from an email?

It can be risky, because HTML attachments are often used for phishing pages. Viewing the code in a sandboxed preview is safer than opening it directly, and you should never enter a password into a page that arrived as an attachment.

Why do my images not show in the HTML viewer?

Relative image paths point to files on your computer that the online viewer cannot reach. Use full https:// URLs or embedded data URIs while testing.

Can I run JavaScript in the HTML viewer?

Yes. Scripts run inside the sandboxed frame and their console output and errors appear in the Console panel, but they cannot access the surrounding site or your cookies.

How do I see what my page looks like on a phone?

Switch the preview to Phone (375px) or Tablet (768px). Make sure your page includes the viewport meta tag, or mobile widths will not behave like real phones.

Does the HTML viewer upload my code?

No. The code is rendered locally in your browser tab. Only resources your HTML links to, such as external images or fonts, are fetched from their own servers.

Try it now: HTML Viewer

Loading tool…