How to Open an HTML File on Any Device
To open an HTML file as a web page, double-click it or drag it into a browser such as Chrome, Safari, Edge or Firefox. To see its code instead, open it with a text editor, or right-click and choose Open with. On a phone, the easiest way is to put the page online and open its link.
An HTML file can be opened in two ways, and most confusion comes from mixing them up. Opened in a browser, it becomes a page with text, colours and buttons. Opened in a text editor, it is plain text full of angle brackets. Both are correct; they just answer different questions. This guide covers both, on every common device, plus what to do when the page opens but looks wrong.
Two ways to open the same file
An HTML file is a text file with instructions for a browser. I explain the anatomy in what is an HTML file, but the key idea is simple: the file is code, and a browser turns that code into a page.
- To see the page, open the file with a browser.
- To see or change the code, open it with a text or code editor.
Your computer decides which one happens when you double-click, based on its default app for .html files. If double-clicking shows the page, your default is a browser. If it shows code, your default is an editor. You can always choose the other one with Open with.
On Windows
As a page. Double-click the file. It opens in your default browser, usually Edge or Chrome. If it opens in something else, right-click the file, choose Open with, and pick a browser. Tick the option to always use that app if you want it as the default.
As code. Right-click the file, choose Open with, then Notepad. For anything more than a quick look, use a proper code editor such as Visual Studio Code, which colours the code and helps you spot mistakes.
Drag and drop. You can also drag the file from File Explorer onto an open browser window or tab.
On a Mac
As a page. Double-click the file. It opens in Safari, or in whichever browser you set as default. To pick another, right-click (or Control-click) the file, choose Open With, and select the browser.
As code. Right-click, Open With, TextEdit. TextEdit may try to show the page as formatted text rather than code; to avoid that, go to TextEdit's settings and turn on the option to display HTML files as code rather than formatted text. A code editor such as Visual Studio Code avoids the problem altogether.
On a Chromebook
Open the Files app, find the HTML file and double-click it. It opens in Chrome as a page. To see the code, open the page in Chrome and press Ctrl+U, which shows the source.
On iPhone and iPad
Phones are where HTML files get awkward. The Files app can preview an HTML file, and Safari can show it, but the experience depends on where the file came from, and pages that load separate styles or images usually arrive broken.
In short: save the file to Files, tap it to preview it, and use the share sheet if you need another app. If the page depends on other files, preview will not find them. The step-by-step version, with the workarounds that do work, is in how to open an HTML file on iPhone.
On Android
On Android, open the file from your Files app and choose Chrome or another browser when asked. Some phones show a list of apps; pick a browser to see the page, or a text editor app to see the code. As with iPhone, pages that depend on separate files often arrive without styles or images.
The easiest way on any phone: open a link
The most reliable way to show an HTML page on a phone is to stop treating it as a file. Put it online and open the link.
Paste the HTML into HTMLpad on your computer, save it, and send yourself the link. On your phone, tap it: the page opens in the browser like any website, styles and all, with no file juggling. This is also the way to show the page to someone else, as I explain in how to share an HTML file as a link.
Open it in a specific browser
Sometimes you want a particular browser, for example to check how a page looks in Firefox when your default is Chrome. Three ways work everywhere:
- Drag the file onto the browser window or onto an open tab.
- Use the browser's open command. Press Ctrl+O on Windows or Cmd+O on a Mac inside the browser, then pick the file.
- Type the path. In the address bar, a file path such as
file:///C:/Users/you/Downloads/page.htmlon Windows orfile:///Users/you/Downloads/page.htmlon a Mac opens it directly.
Checking a page in two or three browsers is worth the minute it takes when the page is going to be seen by many people. Browsers agree on almost everything today, but fonts, form controls and some newer CSS features can still differ slightly.
Files from email, downloads and AI assistants
Where the file came from changes the first step.
Email. Most mail apps show HTML attachments as a preview or as code, and some block them as a precaution. Save the attachment to your computer first, then open the saved file with a browser. If you did not expect the attachment, read the section on safety below before opening it.
Downloads. Files you download land in your Downloads folder. If the page came as a zip, extract it first. Opening an HTML file from inside a zip without extracting it is a common reason for missing styles and images, because the other files stay inside the archive.
AI assistants. ChatGPT, Claude and Gemini often give you HTML as a block of code in the chat, or as a downloadable file. If it is code, copy it into a text editor and save it with a name ending in .html, choosing plain text and UTF-8 if the editor asks. Then open the file with your browser. Even quicker, paste the code into HTMLpad: you see the page immediately, and you can save it as a link if you want to share it.
View the source of any web page
Sometimes the HTML file you want is a page that is already online. Every browser lets you see the code behind it.
- Chrome, Edge and Firefox on a computer: press Ctrl+U on Windows or Chromebook, or Cmd+Option+U on a Mac, or right-click the page and choose View page source.
- Safari on a Mac: first switch on the developer features in Safari's settings, then use Show Page Source from the Develop menu.
- Developer tools: press F12, or right-click any element and choose Inspect, to see the live code and how each part of the page is built. Chrome's DevTools documentation lists every shortcut.
To save a page's HTML, use the browser's Save Page As option. Keep in mind that a saved page is a snapshot, and its links to styles and scripts may still point at the original site.
When the page opens but looks wrong
You double-click the file, the browser opens it, and the result is plain black text on white, or there are boxes where images should be. The file is fine; the browser cannot find something it needs.
No styles. The HTML loads a separate CSS file, and that file is not where the HTML expects it. Keep the CSS file in the same folder structure, or paste its contents into a <style> tag inside the HTML.
Missing images. Same cause. A path like images/logo.png only works if there is an images folder next to the HTML with logo.png in it.
Broken buttons or features. Some pages need a web server to work: they load data from other files or call an API. Browsers apply stricter security rules to files opened from your disk, so these features often fail locally even though the code is fine. Putting the page online usually fixes it.
Strange characters. Accents and symbols that appear as garbled text mean an encoding mismatch. Make sure the HTML includes <meta charset="utf-8"> in its <head> and that the file is saved as UTF-8.
When the file shows code instead of the page
If you expect a page and see code, one of three things is happening.
- It opened in an editor. Use Open with and choose a browser.
- The extension is wrong. A file called
page.html.txtis a text file to your computer. Turn on file extensions in your system settings and rename it to end in.html. - You opened it from a file-sharing service. Cloud drives and email previews often show HTML as code for safety. Download it first, or open it from a link on a real web host.
Opening HTML files safely
An HTML file can contain scripts, and opening one from a stranger is not risk-free. HTML attachments are a common way to deliver phishing pages: the file opens a convincing login form that sends your password elsewhere, as TechRadar has reported.
A few habits keep you safe:
- Do not open HTML attachments you did not expect, even from known senders.
- Never type a password into a page that opened from a file on your computer.
- If you need to look at a suspicious file, open it in a text editor, which only shows the code and runs nothing.
Frequently asked questions
What program opens HTML files?
Any web browser opens HTML files as pages: Chrome, Safari, Edge, Firefox and others. Any text editor opens them as code: Notepad, TextEdit, or a code editor such as Visual Studio Code.
Why does my HTML file open as text?
Either it opened in a text editor, its name does not end in .html, or the app you used shows HTML as code for safety. Right-click the file, choose Open with, and pick a browser.
Can I open an HTML file without internet?
Yes. A browser opens HTML files from your disk without any connection. The page will only be complete if everything it uses, such as styles and images, is also on your disk or inside the file.
How do I open an HTML file on my phone?
Save it to your phone's files app and open it with the browser, or, more reliably, put the page online with a tool like HTMLpad and open the link on your phone.
How do I open HTML code from a website?
Right-click the page and choose View page source, or press Ctrl+U (Cmd+Option+U on a Mac) in Chrome, Edge or Firefox.
