An HTML file is a plain text document that a web browser reads and displays as a webpage

An HTML file is a text file with the .htm or .html extension that contains instructions for how a web browser should display content. When you open an HTML file in a browser like Chrome, Firefox, or Safari, the browser reads the code inside and shows you formatted text, images, links, and other elements. You create HTML files using any plain text editor — Notepad on Windows, TextEdit on Mac, or any other program that saves as plain text — and then save the file with an .htm or .html extension instead of .txt.

The difference between .htm and .html is purely historical and has no practical effect on how your file works. Both extensions tell your computer "this is a web page." Most people use .html because it became the standard, but either works identically.

Key Takeaways

  • Open Notepad (Windows) or TextEdit (Mac), type or paste your HTML code, and save the file with .html as the extension instead of .txt.
  • HTML files are plain text files that contain code — they are not Word documents or PDFs, and you cannot create them in Microsoft Word's default format.
  • Once saved, you can open an HTML file by double-clicking it, and your default browser will display it as a webpage.
  • Organize HTML files in a dedicated folder on your computer so related files (images, stylesheets, other pages) stay together and load correctly.

Creating an HTML file on Windows using Notepad

Open Notepad by pressing the Windows key, typing "Notepad," and clicking the app when it appears. Type or paste your HTML code into the blank document. A basic HTML file looks like this:

<!DOCTYPE html> <html> <head> <title>My Page</title> </head> <body> <h1>Hello World</h1> <p>This is my first webpage.</p> </body> </html>

Once your code is in Notepad, click File, then Save As. In the dialog that opens, navigate to the folder where you want to store the file. In the "File name" field, type a name followed by .html — for example, "mypage.html" or "index.html". Make sure the "Save as type" dropdown is set to "All Files" rather than "Text Documents (.txt)". If you leave it on "Text Documents," Windows will save it as a .txt file and your browser will not recognize it as a webpage. Click Save.

Creating an HTML file on Mac using TextEdit

Open TextEdit by clicking the Finder icon, navigating to Applications, then Utilities, and double-clicking TextEdit. Before you type anything, you must change the format from rich text to plain text. Click Format in the menu bar and select "Make Plain Text." This step is essential — if you skip it, TextEdit will add invisible formatting that breaks your HTML code.

Type or paste your HTML code into the document. Then click File and select Save. In the dialog, give your file a name with the .html extension — for example, "mypage.html". Choose the folder where you want to save it. Click Save. If TextEdit asks whether you want to use the .html extension, click "Use .html".

Why you cannot use Microsoft Word or Google Docs

Microsoft Word and Google Docs are designed for formatted documents, not plain text code. When you type HTML code in Word and save it, Word adds invisible formatting codes that break the HTML. Your browser will not be able to read it correctly. If you only have access to Word, you can use File > Save As and choose "Plain Text (.txt)" as the format, then manually rename the file extension from .txt to .html afterward — but this is more complicated than using Notepad or TextEdit.

Google Docs does not have a plain text save option at all, so it is not suitable for creating HTML files.

Opening and testing your HTML file

Once you have saved your file with the .html extension, you can open it in a web browser by double-clicking it. Your default browser will launch and display the page. If you want to open it in a different browser, right-click the file, select "Open with," and choose the browser you prefer.

To edit the HTML code after you have created the file, right-click it, select "Open with," and choose Notepad (Windows) or TextEdit (Mac). Make your changes, save the file, then refresh the browser window to see the updates.

Organizing HTML files in folders

If your HTML file references images, stylesheets, or other files, those files must be in the same folder or in a subfolder that your HTML code points to correctly. Create a dedicated folder for your project — for example, "My Website" — and save your main HTML file (often named "index.html") inside it. Create subfolders like "images" and "css" inside that folder, and place your image files and stylesheet files there.

When you write code that links to an image, use a relative path like <img src="images/photo.jpg"> instead of an absolute path. This way, if you move your entire project folder to a different location or share it with someone else, all the links still work because the folder structure stays the same.

Common mistakes when saving HTML files

The most common mistake is saving the file with a .txt extension instead of .html. This happens when you use "Save As" but forget to change the file type dropdown from "Text Documents" to "All Files" (Windows) or when you do not confirm the .html extension (Mac). Always double-check the extension in the filename field before you click Save.

Another mistake is typing the code in a formatted editor like Word without converting to plain text first. If your HTML file opens in Notepad instead of your browser when you double-click it, the file was saved as .txt. Right-click it, select Rename, and change the extension from .txt to .html. The file will then open in your browser.

Frequently Asked Questions

What is the difference between .htm and .html?

There is no practical difference. Both extensions tell your computer the file is a webpage. The .htm extension is a holdover from older systems that limited filenames to three characters. Use .html because it is the modern standard, but either one works identically in every browser.

Can I create an HTML file on my phone or tablet?

Yes, but it is more difficult. You need a plain text editor app — not a word processor. On Android, try apps like Jota+ or QuickEdit. On iPhone, try Textastic or a-Shell. Save the file with the .html extension, then open it in your mobile browser to test it. Desktop editing is usually easier for longer or more complex files.

What if I want to add images or links to my HTML file?

Images and links are created using HTML code inside your file. To add an image, use <img src="filename.jpg">. To add a link, use <a href="https://example.com">Click here</a>. Make sure image files are saved in the same folder as your HTML file or in a subfolder you reference correctly in the code.

Do I need internet to create or view an HTML file?

No. HTML files are stored on your computer and open in your browser locally. You only need internet if your HTML code contains links to external websites or loads resources from the web. A basic HTML file with text and local images works completely offline.

Can I edit an HTML file after I save it?

Yes. Right-click the file, select "Open with," and choose Notepad or TextEdit. Make your changes and save the file. Refresh your browser window to see the updates. You can edit an HTML file as many times as you want.