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.
Open an .html file or paste code and see the rendered page Open the free tool
Paste code or drop a file, ZIP or folder. Free plan, custom address, password & editing included. Get a URL