You download an `.html` file from a colleague, export a dashboard from a Python notebook, or save a page generated by an AI tool. You double-click it—and half the page is missing, fonts fall back to Times New Roman, or DevTools throws a wall of red CORS errors about `origin 'null'`.
Nothing is wrong with your browser. You ran straight into the security boundary between `file://` and real HTTP origins.
Three things that break under `file://`
1. ES Modules and `fetch()` are blocked by the opaque `null` origin
When you open a file from your disk (`file:///Users/you/demo/index.html`), modern browsers intentionally assign it an opaque origin of `null` instead of a host. Because `<script type="module">` and `fetch()` enforce CORS, even loading `./app.js` or `./data.json` sitting in the exact same folder fails with `blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, https`. Browsers enforce this so a single downloaded HTML file cannot silently read other sensitive files off your hard drive.
2. Root-relative paths point to your disk root
Any link starting with a leading slash—like `<img src="/logo.png">` or `<link href="/styles.css">`—resolves to `file:///logo.png` (the root of your entire drive) rather than the folder containing your HTML file.
3. Browser storage, History API, and cookies behave inconsistently
`localStorage`, `sessionStorage`, `history.pushState()`, and modern APIs like Clipboard or Web Crypto (`crypto.subtle`) either throw security exceptions or refuse to persist state outside a secure `https://` or `http://localhost` context.
What about safety when you did NOT write the HTML file?
HTML email templates, exported bank statements, and phishing lures all arrive as `.html` attachments. Double-clicking an untrusted `.html` file runs its JavaScript directly in your main browser window—which can trigger tracking pixels, spoof login prompts, or redirect to malicious URLs. Opening it inside a sandboxed viewer lets you inspect the raw markup side by side with a restricted preview before you decide to trust it.
Comparing the 4 ways to open an `.html` file
| Method | Fixes `file://` CORS? | Safe for untrusted files? | Works on phone / non-dev laptop? | Setup time |
|---|---|---|---|---|
| Double-click (`file://`) | No (`null` origin blocks modules & `fetch`) | Low — runs directly in your main browser tab | Desktop only; mobile apps often show raw text | 0 seconds |
| `python3 -m http.server` / `npx serve` | Yes (`http://localhost`) | Low — serves every file in the directory over localhost | No — requires terminal + Python or Node.js | 15-30 seconds |
| VS Code Live Server | Yes (`http://127.0.0.1`) | Low — local dev tool, not an isolation sandbox | No — requires VS Code + extension | 1-2 minutes |
| Sandboxed online viewer (ViewHTML) | Yes for standalone HTML & HTTPS CDN assets | High — preview runs in `<iframe sandbox>` without `allow-same-origin` | Yes — any desktop or mobile browser | 5 seconds (drag & drop) |
Quick local server commands (when you have a multi-file folder)
If your trusted project has local sibling files (`./data.json`, `./app.js`, local images), serve the folder over `localhost` with whichever runtime you already have installed:
# Python 3 (built in on macOS and most Linux machines)
python3 -m http.server 8000
# Node.js
npx serve .If it is a standalone `.html` file—or you want to inspect the source code and rendered layout side by side without opening a terminal—drop it straight into the ViewHTML HTML file viewer. You can inspect the code, verify what it renders, and optionally turn it into a shareable HTTPS link that works on every phone and laptop.
Try the HTML viewer
Paste your HTML into ViewHTML, preview the rendered page, then export the result as a URL, QR code, image, or PDF.
Open Free HTML Viewer