Skip to content

How to Open an HTML File on Windows, Mac, iPhone and Android

By Durim Hoti · Last updated

An HTML file is a plain text file with the page's code. Opening it means one of two things: looking at the finished page, which is a browser's job, or looking at the code, which is a text editor's job. Which way works best depends on the device.

Open an HTML file on Windows

  1. Double-click the file. It opens in your default browser, for example Edge or Chrome.
  2. To choose the browser, right-click the file, select Open with and pick one.
  3. To edit the code, right-click the file and open it with Notepad or another code editor.

While the page is open in Chrome, Edge or Firefox, Ctrl+U shows its source code in a new tab.

Open an HTML file on a Mac

  1. Double-click the file to open it in your default browser, usually Safari.
  2. To use another browser, Control-click the file, choose Open With and pick it.
  3. To edit the code, open the file in a code editor. TextEdit shows HTML files as formatted text by default; its settings have an option to display HTML files as HTML code instead.

Open an HTML file on an iPhone or Android phone

Phones have no built-in app for HTML code, and what the file manager does with an .html file depends on the phone and app. The way that works the same everywhere is the browser:

  1. Open the HTML viewer in Safari, Chrome or your phone's browser.
  2. Tap Open .html file and choose the file from your files or downloads.
  3. Switch between the code and the rendered page. The Mobile, Tablet and Desktop buttons change the preview width.

Example: a file with two images

This file has two images. The first points to a photo in an images folder next to the file, the second is embedded in the file as a data URL:

trip.html (body)
<h1>Trip to the coast</h1>
<p>Photo saved next to this file:</p>
<img src="images/beach.jpg" alt="Beach at sunset" width="240" height="140">
<p>Photo embedded in the file:</p>
<img src="data:image/svg+xml,…" alt="Embedded image" width="240" height="60">

Opened in the HTML viewer, the heading, text and embedded image appear, but the first image only shows its alt text Beach at sunset. The viewer received just the HTML file, not the images folder, so images/beach.jpg doesn't exist for it. Opened with a double-click from the folder on your computer, the same file shows both images, because the browser can read the folder.

The HTML viewer with trip.html open: the code on the left, and on the right the rendered page with the heading, a broken first image showing the alt text Beach at sunset, and a blue embedded image that displays correctly.
trip.html in the HTML viewer: the relative image is missing, the embedded one shows.

Common problems

Images or styles are missing

The file links to images or a stylesheet with relative paths, and the browser can't reach them. Keep the file in its original folder and open it from there, or change the links to full https:// addresses. Small images can be embedded as data URLs, which you can create with the image to Base64 converter.

The browser shows code instead of the page

The file probably isn't really an .html file. Windows hides file extensions by default, so page.html saved from Notepad can end up as page.html.txt. Turn on file name extensions in File Explorer and rename it, or choose All files as the type when saving.

Letters like é or ü look broken

The file uses an older encoding than UTF-8, or doesn't say which one it uses. Add <meta charset="utf-8"> to the <head> and save the file as UTF-8 in your editor. The HTML viewer always reads files as UTF-8.

The file opens in Word

Word can open HTML files, but it shows its own interpretation of the page. Open the file with a browser to see what visitors see.

What to do next

To change the page and see the result as you type, paste the code into the online HTML editor; our guide on running HTML, CSS and JavaScript online explains how. To share the page as a document, see how to convert HTML to PDF.

FAQ

Can I open an HTML file without an internet connection?
Yes. A browser opens a local .html file without going online. Anything the file loads from the web, such as a font or an image on another site, is missing until you are online again.
Why does my HTML file open in Word or Notepad instead of a browser?
Your computer has a different app set as the default for .html files. Right-click the file and use Open with to pick a browser for this time, or change the default app for .html files in your system settings.
Is my file uploaded when I open it in the online HTML viewer?
No. The viewer reads the file in your browser and shows it in an isolated frame on your device. The file is not sent to a server. Only resources the file itself links to, such as images on other websites, are loaded from those sites.
How do I see the HTML code of a website, not a file?
In Chrome, Edge and Firefox on a computer, press Ctrl+U (Cmd+Option+U on a Mac in Chrome) or type view-source: in front of the address. To work with that code, copy it into the HTML viewer or editor.
Which files does the HTML viewer open?
Files ending in .html, .htm and .xhtml, and SVG images (.svg). It reads them as UTF-8 text.

Try it and keep reading