Skip to content

HTML Viewer with Live Preview

Paste HTML or open an HTML file to see it render live. Switch to a phone or tablet width and inspect console output while you work.

Runs in your browser Free, no sign-up
Loading tool workspace...

What is an HTML viewer?

An HTML viewer turns HTML code into the page it describes. A browser does this for every website you visit; an HTML viewer online does it for code you paste or open yourself, so you can preview HTML code without saving a file, setting up a server or uploading anything.

This one shows the source and the rendered page side by side. Inline CSS and JavaScript work, and the preview uses your browser's own engine, so it's also an HTML5 viewer: every element, CSS feature and script API your browser supports works here. Use it as an HTML code viewer for a full page, or as an HTML previewer for a snippet from a tutorial, an email template or a component you're building.

Key facts

Files you can open.html, .htm, .svg, .xml, .css, .js, .md or .txt, with Open file or by dropping the file on the tool. CSS and JavaScript files are placed in a blank page so they have something to style or run in; the other types are loaded as they are and rendered as HTML (Markdown isn't converted).
File size limit10 MB per file. Larger files are turned away with a message.
Preview widthsDesktop (the full preview pane), Mobile 375 × 667 px, Tablet 768 × 1024 px, and Custom from 240 to 3,840 px wide. Rotate swaps width and height for Mobile and Tablet. A frame wider than the pane is scaled down to fit, with the zoom level shown; its CSS width, which media queries use, stays the same.
UpdatesThe preview refreshes 250 ms after you stop typing, and up to 2 seconds for large documents. Documents over 1,000,000 characters open with Auto-update off; Run or Ctrl+Enter refreshes on demand.
SandboxThe preview is an iframe with sandbox="allow-scripts"and nothing else. JavaScript runs, but the page has no origin of its own: cookies, localStorage, sessionStorage and IndexedDB throw a SecurityError, forms don't submit, pop-ups and dialogs are blocked, and it can't read or navigate this site. Frames inside your page inherit the same limits.
Consoleconsole.log, info, warn, error, debug, table and assert; uncaught errors with their line and column; unhandled promise rejections; and images, scripts or stylesheets that fail to load. alert(), confirm() and prompt() show their message here instead of a dialog. Up to 500 messages per run, with repeats counted rather than listed again.
LinksLinks to #sections scroll the preview. Other links aren't followed, so the preview never leaves your page; the console notes each one. In the full-tab view (Open preview in new tab), links work.
Relative pathsPaths such as images/logo.png point at relative-path.invalid, an address that can never exist, so they fail in your browser instead of requesting files from this site. A <base href> in your own code takes precedence.
UploadsNone. What you type, the files you open and the preview all stay in this browser tab.
Share linksThe code is compressed (deflate-raw) and stored after #code= in the link. Browsers never send that part of a URL to a server, but anyone who has the link can read the code. Links over 8,000 characters get a warning, and 2,097,152 characters is the maximum. A shared link opens with a notice, and nothing runs until you click Run shared code.

Features

  • Live preview that refreshes as you type, or on Run (Ctrl+Enter)
  • Open or drop .html, .htm, .svg, .xml, .css, .js, .md or .txt files up to 10 MB
  • Mobile (375 px), Tablet (768 px), Desktop and custom widths, with rotate
  • Full screen, or the preview in its own tab
  • Console for logs, errors and failed files, with line numbers
  • Checks for a missing doctype, unclosed tags, duplicate ids, relative paths, http:// files and template tags
  • Format, Copy, Download .html and share links
  • Open the code in the HTML Formatter, HTML Validator or HTML Minifier
  • Side-by-side or stacked layout
  • Sandboxed preview, and nothing is uploaded

How to view HTML online

  1. Paste or type HTML in the HTML source pane, or click Open file (or drop a file anywhere on the tool) to load an .html file up to 10 MB.
  2. Watch the preview refresh as you type. Switch Auto-update off to refresh only when you click Run or press Ctrl+Enter.
  3. Above the preview, choose Desktop, Mobile, Tablet or Custom to set its width, and Rotate for landscape. The full-screen and new-tab buttons give the page more room.
  4. Open the Console tab under the preview for messages and errors, and the Checks tab for markup problems. Click a line number to jump to that line in the source.
  5. Click Format to indent the markup, then Copy it, Download .html, create a Share link, or use Open in to carry on in the HTML Formatter, HTML Validator or HTML Minifier.

Example: the same page at desktop and phone width

Load sample puts this page in the editor: three pricing cards in a CSS grid, and one media query that changes the layout on screens 480 px wide or narrower.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Pricing plans</title>
  <style>
    body { font-family: system-ui, sans-serif; margin: 24px; color: #1f2937; }
    .plans { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
    .plan { border: 1px solid #d1d5db; border-radius: 12px; padding: 16px; }
    .plan h2 { margin: 0 0 8px; font-size: 18px; }
    .badge { display: inline-block; background: #ede9fe; color: #5b21b6; border-radius: 999px; padding: 2px 10px; font-size: 12px; }
    @media (max-width: 480px) {
      .plans { grid-template-columns: 1fr; }
      .badge { display: none; }
    }
  </style>
</head>
<body>
  <div class="plans">
    <section class="plan"><h2>Starter</h2><p>$0 per month</p></section>
    <section class="plan"><h2>Team</h2><span class="badge">Most popular</span><p>$12 per month</p></section>
    <section class="plan"><h2>Business</h2><p>$29 per month</p></section>
  </div>
  <p><button type="button" id="measure">Log the width</button></p>
  <script>
    const report = () => console.log("Viewport width:", window.innerWidth + "px");
    document.getElementById("measure").addEventListener("click", report);
    report();
  </script>
</body>
</html>
In the previewDesktop (pane wider than 480 px)Mobile (375 px)
LayoutThree cards side by sideOne card per row
“Most popular” badgeShown on the Team cardHidden
Console after Log the widthViewport width: the pane's width in pxViewport width: 375px

Tablet (768 px) shows three columns, because 768 is wider than 480. The Mobile frame is drawn smaller when the pane is narrow, but its CSS width stays 375 px, so the media query matches exactly as it would on a 375 px phone.

Ways to open and view an HTML file

Each way of opening an .html file shows you something different. To open an HTML file online without installing anything, use Open file above; to view an HTML file as its visitors will, use a browser.

MethodWhat you seeRuns JavaScriptBest forWatch out for
Double-click the file (your default browser)The rendered pageYesChecking a finished page with its images and CSS in the same folderWithout a doctype it renders in quirks mode; phone sizes need the browser's DevTools
Text editor (Notepad, VS Code, TextEdit)The source codeNoEditing the fileTextEdit saves rich text unless you choose Format › Make Plain Text
Browser View Source (Ctrl+U) or DevTools (F12)The file as loaded, or the live page structure, styles and consoleYes, in the pageInspecting a page that's already openView Source shows the file before scripts change it; DevTools shows it after
Microsoft WordAn approximation of the page in Web Layout viewNoCopying text out of a pageMuch of the CSS layout is lost, and saving from Word can rewrite the markup with Word's own styles
This HTML viewerThe source with a live HTML code preview beside itYes, sandboxedQuick previews, phone and tablet widths, console and checks, sharingImages and stylesheets referenced by relative paths don't load; use full https:// URLs

Common mistakes the Checks tab catches

The Checks tab runs the same rules as the HTML Validator, plus checks for problems that only show up when a page is previewed. Every finding has a line number you can click.

No doctype, or not at the top

Without <!DOCTYPE html>as the first thing in the file, browsers render the page in quirks mode, an old compatibility mode where percentage heights, text size in tables and lengths without units behave differently. The preview itself always renders in standards mode, because browsers never use quirks mode for an iframe's srcdoc document, so a page can look right here and wrong once the saved file is opened. The warning is about the file.

Relative paths to images and stylesheets

<img src="images/logo.png">expects an images folder next to the HTML file. Pasted code has no folder, so the image can't load and the console reports it. Use a full https:// URL or a data: URI.

http:// files on an https page

This page is served over https, and so is the preview. Browsers block scripts, stylesheets and frames requested over http:// on such a page, and retry images, audio and video over https, which fails when the server doesn't offer it. Change the URLs to https://.

PHP and template tags

A browser runs only HTML, CSS and JavaScript. <?php echo $title; ?>is read as a comment that ends at the first >, so its output is missing, and template syntax such as {{ name }}, {% if %} or <% %> shows as plain text. To preview a server-rendered page, copy the HTML the server sends (View Source) instead of the template.

Unclosed and misnested tags

Browsers repair broken markup silently, so a missing </div> can wrap the rest of the page in one element, and a <div> inside a <p> ends the paragraph early. The checks point to the tag that was left open and where it ended up closed, and flag duplicate id values as well.

Use cases

  • Debugging a layout. Paste the markup and CSS of a broken section, step through Mobile, Tablet and Custom widths to find where it breaks, and edit until it holds.
  • Prototyping components. Build a card, navigation bar or form in one file with its style and script, watch it update as you type, and download it when it works.
  • Testing embed codes. Paste an iframe or script embed to check its size and placement. Embeds that don't rely on cookies, such as map frames, display normally; players and widgets that need their own cookies or storage, such as YouTube, can show an empty box, because frames inside the preview inherit its sandbox.
  • Previewing HTML emails. Check an email's HTML at desktop width and at 375 px. A browser supports more CSS than most email clients, so treat this as a first check and send yourself a test before the real thing.
  • Learning HTML. Change a tag or a CSS property and see the effect straight away; the console and checks explain mistakes with line numbers.

Tidy messy markup with the HTML Formatter, which this viewer's Format button also uses. Check a page against HTML's nesting rules in the HTML Validator, then shrink it for production with the HTML Minifier. To show markup as text on a web page, escape it with the HTML Escaper, and to put a whole page in a data: URI, convert it with HTML to Base64.

Frequently asked questions

How do I view an HTML file?

Open it in a web browser: double-click the file, or drag it onto an open browser window. To see the code and the page side by side, click Open file above or drop the file onto this page. It accepts .html, .htm, .svg, .xml, .css, .js, .md or .txt files up to 10 MB, and the file never leaves your device.

How can I view HTML online?

Paste the code into the HTML source pane at the top of this page. The preview next to it renders the page as you type with your browser's own engine, so it works on any device with a current browser, and nothing is sent to a server.

How do I open an HTML file in Chrome?

Drag the file into a Chrome window, or press Ctrl+O (Cmd+O on a Mac) and pick it; the address bar then shows a file:/// path. On Windows you can also right-click the file and choose Open with › Google Chrome. Press Ctrl+U (Cmd+Option+U on a Mac) to read the page's source.

Why won't my HTML file open in the browser?

Often the file isn't really an .html file. Windows hides known extensions, so index.html can actually be index.html.txt, and Mac TextEdit saves rich text unless you choose Format › Make Plain Text. If the file opens but the page is blank or cut off, an unclosed comment, tag or <script> is probably swallowing the content. Open it here and the Checks tab shows the line.

Is it safe to open an HTML file?

An HTML file runs like any web page, with the same limits a website has, but its scripts can still load content from the internet and show convincing forms. Be wary of HTML attachments from people you don't know, especially ones that ask you to sign in, a common phishing trick. In this viewer the code runs in a sandbox with no access to cookies or storage, no form submission, no pop-ups and no way to navigate this page.

Can Microsoft Word open HTML files?

Yes. Word opens .html and .htm files in Web Layout view, but it doesn't run JavaScript and drops much of the CSS layout, so the page rarely looks the way a browser shows it. Saving from Word can also rewrite the markup with Word's own styles. To see the page as visitors will, open it in a browser or in this viewer.

How do I see how my HTML looks on mobile?

Choose Mobile (375 × 667 px) or Tablet (768 × 1024 px) above the preview, or Custom for any width from 240 to 3,840 px, and use Rotate for landscape. The frame keeps that CSS width even when it's scaled down to fit, so media queries respond as they would on the device. For real phones, also put <meta name="viewport" content="width=device-width, initial-scale=1"> in the page's head.

How do I preview an HTML email?

Paste the email's HTML and check it at Desktop and Mobile widths. That shows how a browser renders it. Email clients such as Outlook and Gmail support less CSS and remove scripts, so use the preview to catch layout mistakes early, then send yourself a test email before the real one.

Can I run HTML code with JavaScript in the preview?

Yes. Scripts run in an iframe sandboxed with allow-scripts only, and their console messages and errors appear in the Console tab with line numbers. The sandbox gives the page no origin of its own, so cookies, localStorage, sessionStorage and IndexedDB throw a SecurityError, forms don't submit, and alert(), confirm() and prompt() show their message in the console instead of opening a dialog.

Why don't my images or CSS load?

A relative path such as images/logo.png means “next to this HTML file”, and pasted code has no folder around it, so the request fails. Use full https:// URLs, or embed small images as data: URIs with the Image to Base64 Converter. Files requested over http:// are blocked or switched to https on this https page. The Checks tab lists both problems with their line numbers.

Can I share an HTML preview with someone?

Yes. Share link compresses the code into the link itself, after #code=, and copies it. Browsers don't send that part of a link to any server, so the code isn't uploaded anywhere. Whoever opens the link sees the code and a notice first, and it runs only when they click Run shared code. Links over 8,000 characters can get cut off in chats or email; send the file from Download .html instead.

What's the difference between an HTML viewer and an HTML formatter?

A viewer renders HTML so you see the page it describes; a formatter rewrites the HTML itself with consistent line breaks and indentation so it's easier to read. This viewer's Format button uses the same formatter as the HTML Formatter tool, and Open in › HTML Formatter takes your code there.

Can I view HTML and CSS together?

Yes. Put the CSS in a <style> block or in style attributes and the preview applies it as you type, so it works as an HTML and CSS viewer for a single page. Opening a .css file places it in a <style> block inside a blank page; add your HTML under <body> to see it styled. A <link> to a stylesheet on your computer can't load, because pasted code has no folder around it.

Can I view HTML on Android or iPhone?

Yes. Open this page in the browser on your phone; there is no app or APK to install. Paste the code, or tap Open file and pick an .html file from your phone's storage, and it renders in the preview. The file is read on your device and never uploaded.

How do I open an .html file on my phone?

Phone file managers often open .html files as plain text or not at all. Open this page in your phone's browser, tap Open file, choose the .html file, and the page renders next to its code. Use Mobile or Tablet width to check the layout.

Can it display SVG files?

Yes. Open an .svg file or paste <svg> markup, and the preview draws it the way a browser draws SVG inside a web page, including any CSS and scripts it contains. Resize the preview with the Desktop, Mobile, Tablet or Custom widths to see how an SVG without fixed dimensions scales.

More formatters & viewers tools

View all