Beginner guides › Save and open an HTML file
How to save and open an HTML file
To save a web page as an HTML file, open it and press Ctrl+S (Cmd+S on a Mac). To save HTML code as a file, paste it into a plain text editor, save it with a name ending in .html, then double-click it to open it in your browser. Step by step for Mac, Windows, Chromebook, iPhone and Android, plus converting to PDF or Word.
Which do you need?
- Saving a page from a website, to keep a copy or read it offline? Go to Save a web page as an HTML file. It takes one shortcut.
- Turning HTML code into a file you can open? Keep reading. Your code probably came from one of these:
- a tutorial, course or help page with code boxes (most have a Copy button above the code)
- an email, message or document someone sent you
- the code behind a web page, which you can see by pressing Ctrl+U (Option+Cmd+U in Safari)
- a template, an online code editor such as CodePen, or a tool that generated it for you
- Already got a file ending in .html, for example a download or an attachment? You don't need to save anything: skip to Open an HTML file.
An HTML file is just plain text saved with .html at the end of its name. When you open it, your computer shows it in your web browser instead of as text. The one thing that trips people up is the text editor quietly saving the wrong kind of file, such as page.html.txt. The steps below avoid that.
Save a web page as an HTML file
To keep a copy of a page you're looking at online, open it and press Ctrl+S (Cmd+S on a Mac), or use the browser's menu.
- Chrome and Edge: press Ctrl+S (or open the ⋮ or … menu and choose Save as / Save page as). Choose Webpage, HTML only for one file, or Webpage, Complete to also save its pictures in a folder next to it.
- Safari on a Mac: choose File › Save As and set Format to Page Source for an .html file. Web Archive keeps everything in one file but only opens in Safari.
- Firefox: press Ctrl+S (Cmd+S on a Mac) and choose Web Page, complete or Web Page, HTML only.
- iPhone and iPad: in Safari tap Share, tap Options at the top and choose Web Archive or PDF, then tap Save to Files.
- Android: in Chrome tap ⋮ and then the download arrow. The page is saved to your Downloads to read offline.
Saved pages sometimes lose their layout. If you want a copy that looks exactly right, saving as a PDF is often more reliable.
Save an HTML file on a Mac, with TextEdit
Open TextEdit in plain text mode
Press Cmd+Space, type TextEdit and press Enter. Click New Document, then choose Format › Make Plain Text (or press Shift+Cmd+T). Do this before you paste.
Copy the code and paste it in
Go to where your code is, select all of it and press Cmd+C (or click the Copy button above a code box). Back in TextEdit, paste with Cmd+V. A full page usually starts with
<!DOCTYPE html>and ends with</html>, so check you've got both ends.Save it with .html at the end
Choose File › Save, type a name ending in .html, such as page.html, pick a folder you'll find again (Desktop or Documents) and click Save. If TextEdit asks whether to use .html or .txt, choose Use .html.
Double-click to open it
Find the file in Finder and double-click it. It opens in Safari, or whichever browser you use.
Two one-time settings make this easier. In TextEdit › Settings › New Document, choose Plain text so you never have to switch. In Open and Save, tick Display HTML files as HTML code instead of formatted text, so TextEdit shows the code when you reopen the file.
Save an HTML file on Windows, with Notepad
Copy the code
Go to where your code is, select all of it and press Ctrl+C (or click the Copy button above a code box). A full page usually starts with
<!DOCTYPE html>and ends with</html>, so check you've got both ends.Open Notepad and paste
Press the Windows key, type Notepad and press Enter. Paste your code with Ctrl+V.
Save it as .html
- Choose File › Save as.
- Pick a folder you'll find again, such as Documents or Desktop.
- Set Save as type to All files (*.*).
- Type a name ending in .html, for example page.html.
- Leave Encoding as UTF-8 and click Save.
Why "All files"? Without it, Notepad can add .txt and you get page.html.txt, which opens as text instead of a page. Typing the name in quotes, like "page.html", also works.Double-click to open it
Find the file in File Explorer and double-click it. It opens in your default browser (Edge, Chrome or Firefox).
Save an HTML file on a Chromebook
Open the Text app
Open the Launcher and search for Text. If you don't have it, install the free Text app from the Chrome Web Store or Google Play.
Paste and save
Copy your code, paste it in with Ctrl+V, then choose Save as. Save it in My files › Downloads with a name like page.html.
Open it in Chrome
Open the Files app, find your file and double-click it. It opens in Chrome.
Open an HTML file in your browser
Double-clicking works on most computers. If it opens in the wrong program, or you want a particular browser, use one of these:
- Drag and drop: drag the file from File Explorer or Finder onto an open browser window or tab.
- Open with: right-click the file (on a Mac, Control-click), choose Open with and pick Chrome, Edge, Firefox or Safari.
- From the browser: press Ctrl+O (Cmd+O on a Mac) in Chrome, Edge or Firefox, or choose File › Open File in Safari, then pick the file.
Save and open an HTML file on a phone
Phones are fine for opening an HTML file you've been sent, but awkward for writing one, because they don't come with a plain text editor. If you can, save the file on a computer.
iPhone and iPad
- Save it: if the file is an email attachment or a download, tap it, then tap the Share button and choose Save to Files. Safari downloads go to Files › Downloads on their own.
- Open it: open the Files app, find the file and tap it. You'll see a preview of the page.
Android
- Save it: downloads and saved attachments go to the Download folder.
- Open it: open the Files app (or Files by Google), tap the file and choose Chrome if it asks which app to use.
file:///sdcard/Download/ in Chrome's address bar and tap your file.Convert an HTML file to PDF, Word or text
You don't need a converter website for any of these. Your browser and the programs you already have can do it.
- HTML to PDF: open the file in your browser, press Ctrl+P (Cmd+P on a Mac) and set the printer to Save as PDF. In Safari on a Mac you can also choose File › Export as PDF.
- HTML to PDF on iPhone: open the page, tap Share › Print, then tap the Share button at the top of the print screen and choose Save to Files.
- HTML to Word: in Word, choose File › Open and pick the .html file (set the file type to All files if you can't see it). Then use File › Save as and choose Word Document (.docx).
- HTML to plain text: open it in your browser, select everything (Ctrl+A or Cmd+A), copy and paste into any document.
- HTML to an image: open it in your browser and take a screenshot (Windows+Shift+S on Windows, Shift+Cmd+4 on a Mac).
- Text file to HTML: if the file already holds HTML code, just rename it so it ends in .html instead of .txt. On Windows, turn on file name extensions first (see Quick fixes below). On a Mac, choose Use .html when Finder asks.
Edit and update your file
- Open your file in the editor. On Windows, right-click it and choose Open with › Notepad. On a Mac, right-click and choose Open With › TextEdit.
- Make your changes, or select everything (Ctrl+A, or Cmd+A on a Mac) and paste a new version over it.
- Save (Ctrl+S or Cmd+S).
- Go back to the browser tab and refresh (F5, or Cmd+R on a Mac).
Quick fixes and questions
Why does my HTML file open as text or code instead of a page?
It was saved as a .txt file or as rich text. On Windows, check Save as type was All files. On a Mac, make sure you chose Format › Make Plain Text before saving. Then save it again with .html at the end.
How can I see whether the name ends in .html or .txt?
Windows hides file endings by default. In File Explorer, choose View › Show › File name extensions (on Windows 10, tick File name extensions on the View tab). On a Mac, select the file and press Cmd+I to see its full name.
Why is the page blank?
Usually the code is incomplete. It should finish with </html>. Copy it again, making sure you get everything, and save over the old file. If you only copied a snippet from a tutorial, it may need the rest of the page around it: look for the full example on the same page.
Why do strange symbols like ’ appear in the text?
The file wasn't saved as UTF-8. Save it again and pick UTF-8 as the encoding. Adding <meta charset="utf-8"> near the top of the code also fixes it.
It opens in the wrong program. How do I change that?
Right-click the file and choose Open with, then pick your web browser. On Windows choose Choose another app and tick Always use this app. On a Mac, choose Get Info, pick a browser under Open with and click Change All.
Can I save an HTML file in Google Drive?
Yes, upload it like any other file to store or share it. Drive won't run the page, though: its preview shows the code. To use the page, download it and double-click it, or put it online with free hosting.
Do I need special software to make an HTML file?
No. Notepad on Windows and TextEdit on a Mac are enough. Free code editors such as Visual Studio Code add colours and helpful extras if you start writing HTML often.