Skip to content
Share & open HTML

Why your HTML file opens as code instead of a web page

You open the file and see a wall of tags instead of the page. It is almost always one of five causes, and each has a one-minute fix.

6 min readUpdated October 2026By the HTMLtoURL.dev team
Short answer

An HTML file shows code when it is opened by something other than a web browser — a text editor, a phone's file viewer, or a cloud drive's preview — or when it is served as text/plain. Open it with a browser (right-click → Open with → Chrome), make sure the name really ends in .html and not .html.txt, or host it and open the URL.

Cause 1 — It opened in a text editor

On Windows, a file association may send .html to Notepad or VS Code; on a Mac, to TextEdit. Fix: right-click the file → Open with → choose Chrome, Edge, Firefox or Safari. To make it permanent, pick Choose another app → Always use this app (Windows) or Get Info → Open with → Change All (macOS).

Cause 2 — The file is really named .html.txt

Windows hides known extensions by default, so a file saved from Notepad as "page.html" can actually be page.html.txt. In File Explorer choose View → Show → File name extensions and rename it. In TextEdit on a Mac, use Format → Make Plain Text before saving, or the file is saved as rich text with HTML-looking content.

Cause 3 — A cloud drive is previewing it

Google Drive, OneDrive, Dropbox and iCloud deliberately show HTML as source code (or offer a download). This is a security decision — rendering arbitrary HTML on their domains would let anyone run scripts there — and there is no setting to change it. Fix: download the file and open it in a browser, or host it somewhere designed for web pages and share that link. See why Google Drive no longer hosts HTML.

Cause 4 — A phone opened it in a document viewer

Android "HTML viewer" apps and the iPhone Files preview often show the markup. On Android, choose Open with → Chrome in the Files app; on iPhone there is no "open in Safari" option for local files, so the easiest route is an online HTML viewer or hosting it. Full walkthrough: open an HTML file on a phone.

Cause 5 — The server sends it as text/plain

Web servers tell the browser what a file is with the Content-Type header. If it says text/plain instead of text/html, every browser shows the code. This happens with raw GitHub links (raw.githubusercontent.com), paste sites, some S3 buckets with wrong metadata, and misconfigured servers. Check in DevTools → Network → the file → Headers. Fix: use a host that sets text/html (GitHub Pages instead of raw links; correct metadata on S3), or publish it with an HTML to URL converter.

Bonus — the page opens but looks broken

If you see the page but with no styling, missing images or a plain white layout, the HTML is fine and the other files are missing — CSS, images and scripts referenced with relative paths. Keep them in the same folder structure and upload the whole folder or a ZIP.

Online HTML Viewer
Open an .html file or paste code and see the rendered page
Open the free tool
Convert your HTML to a URL now
Paste code or drop a file, ZIP or folder. Free plan, custom address, password & editing included.
Get a URL

Questions people ask

Why does Chrome show my HTML code instead of the page?

Either the file is served as text/plain (common with raw GitHub and paste links), or the address starts with view-source:. Open the file directly or host it with the correct content type.

How do I make an HTML file open in a browser by default?

Windows: right-click → Open with → Choose another app → pick your browser → Always. macOS: Get Info → Open with → choose the browser → Change All.

Why does my HTML show as code in Google Drive?

Drive intentionally does not render HTML. Download it or host it on an HTML host.

Read next

Paste HTML. Get a URL.

Code, an .html file, a ZIP or a whole folder becomes a live HTTPS URL with your own address, an optional password and a QR code. Free to start with Google sign-in; paid plans keep URLs online for good.

Convert HTML to URL