Save an HTML file by using File > Save As in your text editor, choosing a location on your disk, naming it with the .html extension, and selecting Plain Text format

An HTML file is a plain text document that contains the code a web browser reads to display a webpage. You save it the same way you save any text file — by telling your editor where to put it and what to call it. The key difference is the file extension: it must end in .html (or .htm, which works the same way). Without that extension, your browser will not recognize it as a webpage.

The process takes about 30 seconds and works the same in every text editor: Notepad, Visual Studio Code, Sublime Text, or any other program you use to write code. You do not need special software or a web server. Once saved, you can open the file in any web browser and see the page it describes.

Key Takeaways

  • HTML files must be saved with the .html or .htm extension, or browsers will not recognize them as webpages.
  • Use File > Save As in your text editor, not File > Save, so you can choose the file extension and format.
  • Save the file as Plain Text format, not Rich Text or Word format, or the HTML code will not work.
  • Once saved, you can open the file directly in any web browser by double-clicking it or dragging it into the browser window.
  • The file location does not matter — your computer, a USB drive, or a folder on your desktop all work equally well for viewing locally.

The steps to save an HTML file in a text editor

Open your text editor and write or paste your HTML code. Then go to the File menu at the top left and click Save As (not just Save, because Save will not let you choose the file extension). A dialog box will appear asking where you want to save the file and what to name it.

Type a name for your file — something like index.html, mypage.html, or contact.html. The name itself can be anything, but it must end with .html. Choose a location you can find again: your Desktop, Documents folder, or a dedicated folder for your projects. Then look for a dropdown menu that says Save as type or Format. Change it from Word Document or Rich Text to Plain Text or Text Document. Click Save.

If you are using Notepad on Windows, the Save As dialog may have a field called Encoding. Leave it set to UTF-8. If you see a field for Line endings, leave it as is. These settings rarely cause problems, but UTF-8 is the standard for web code.

Why the .html extension matters

The .html extension tells your operating system and your web browser that this file contains webpage code. Without it, Windows or Mac will treat the file as a generic text document. When you try to open it, the system may ask which program to use, or it may open in Notepad instead of your browser.

The extension .htm works identically to .html — both are recognized by all browsers and all operating systems. The difference is historical: older Windows systems limited file extensions to three letters, so .htm was used. Today, .html is more common, but either one is correct. Pick one and stick with it for consistency.

If you save a file as mypage.txt or mypage with no extension, your browser will not know it is a webpage. You can still open it in a browser by right-clicking and choosing "Open with" and selecting your browser, but the browser will display the raw code instead of rendering the page.

Saving in different text editors

Visual Studio Code (a free editor used by many developers) works like this: write your code, press Ctrl+Shift+S (or Cmd+Shift+S on Mac), type your filename with the .html extension, and click Save. The editor will automatically recognize the .html extension and format the file correctly.

Notepad (built into Windows) requires you to go File > Save As, type your filename in quotes like "mypage.html" (the quotes prevent Notepad from adding .txt automatically), set the file type dropdown to All Files, and click Save. On Mac, the built-in TextEdit requires you to go Format > Make Plain Text before saving, or the file will be saved in a format browsers cannot read.

Sublime Text and other paid editors work the same way as Visual Studio Code: File > Save As, type the filename with .html, and save. These editors are optional — Notepad or any free text editor works just as well for learning HTML.

Opening your HTML file in a web browser

Once you have saved your file, open it in a web browser to see how it looks. The simplest way is to find the file on your computer, right-click it, and choose Open with, then select your browser (Chrome, Firefox, Safari, or Edge). You can also drag the file directly into an open browser window, and it will display the page.

Alternatively, open your browser, press Ctrl+O (or Cmd+O on Mac), and navigate to the file location. Select your HTML file and click Open. The browser will read the code and display the rendered webpage.

Every time you edit the HTML file and save it, you can refresh the browser (press F5 or Ctrl+R) to see the changes. This is how developers test their code locally before uploading it to a web server.

Common mistakes when saving HTML files

The most common error is saving the file in the wrong format. If you use Microsoft Word or Google Docs, these programs add extra formatting that breaks HTML code. Always use a plain text editor like Notepad, Visual Studio Code, or Sublime Text. If you accidentally saved in Word format (.docx), open the file in a text editor, go File > Save As, and resave it as Plain Text with the .html extension.

Another mistake is forgetting the .html extension entirely. If you save a file as mypage instead of mypage.html, your browser will not recognize it. You can fix this by renaming the file: right-click it, choose Rename, and add the .html extension to the end.

A third mistake is saving with spaces or special characters in the filename. While modern systems handle this, it is cleaner to use hyphens or underscores instead: my-page.html or my_page.html instead of my page.html. This matters more when you upload files to a web server, but it is a good habit to start now.

Uploading your HTML file to the web later

Saving an HTML file on your computer lets you view it locally, but only you can see it. To make it visible on the internet, you need to upload it to a web server — a computer that runs 24/7 and is connected to the internet. Web hosting companies like GoDaddy, Bluehost, or Namecheap rent space on their servers and provide tools to upload your files.

Once you upload your HTML file to a web server, people anywhere can visit your website by typing your domain name into their browser. The process of uploading is different from saving locally — you use an FTP client or a file manager built into your hosting account — but the HTML file itself stays the same. Save it correctly now, and uploading later will be straightforward.

Frequently Asked Questions

Can I save an HTML file with a different extension like .txt or .web?

Technically you can, but browsers will not recognize it as a webpage. Use .html or .htm only. If you save as .txt, the browser will display the raw code instead of rendering the page. Other extensions like .web do not work with any standard browser.

What happens if I save an HTML file to a USB drive instead of my computer?

It works exactly the same way. You can save to a USB drive, an external hard drive, or any storage device. The file will open in your browser just as it would from your Desktop. This is useful if you want to carry your HTML files between computers.

Do I need to save HTML files in a specific folder?

No. For learning and testing, you can save anywhere — Desktop, Documents, or a folder you create. When you upload to a web server later, the server has specific folder rules, but for local viewing, location does not matter.

Can I edit an HTML file after I save it?

Yes. Open the file in your text editor, make changes, and save again (Ctrl+S). Refresh your browser to see the updates. You can edit and save as many times as you want.

What if my browser shows the code instead of the rendered page?

This usually means the file was not saved with the .html extension. Right-click the file, choose Rename, and add .html to the end. Then open it in your browser again. If it still shows code, the file may be in Rich Text or Word format — open it in a text editor, go File > Save As, and resave as Plain Text with the .html extension.