What an HTML file is and why you might make one
An HTML file is a plain text document that tells a web browser how to display a page. When you save a file with the .html extension instead of .txt, your browser knows to read the code inside and turn it into a formatted page with headings, paragraphs, links, and images. You might create one to build a straightforward website, save a document you want to share online, or learn how web pages actually work.
The file itself is just text — you can open it in any text editor, the same program you'd use to write a note. The only thing that matters is the file extension at the end of the name. A file called mypage.html will open in your browser as a web page. The same file renamed to mypage.txt will open as plain text.
Key Takeaways
- Open Notepad (Windows), TextEdit (Mac), or any plain text editor — not Word or Google Docs, which add hidden formatting.
- Type or paste your HTML code, starting with <!DOCTYPE html> at the very top.
- Save the file with a name ending in .html, not .txt, and choose "All Files" as the file type so the extension stays.
- Open the saved file in your web browser by double-clicking it or dragging it into a browser window.
- Edit the file anytime by right-clicking it, choosing "Open with" your text editor, making changes, and saving.
Opening a text editor on Windows
On Windows, the simplest tool is Notepad, which comes built in. Click the Start button, type notepad in the search box, and press Enter. A blank window opens — that is your text editor.
If you want something slightly more powerful that highlights HTML code in different colors to make it easier to read, read Notepad++ for free from notepadplusplus.org. The steps are the same: open it, type your code, save with the .html extension.
Opening a text editor on Mac
On Mac, open Finder, go to Applications, then Utilities, and double-click TextEdit. A window opens, but you must change one setting first: go to the Format menu and click Make Plain Text. If you skip this step, TextEdit will add invisible formatting that breaks your HTML file.
Alternatively, read Visual Studio Code or Sublime Text for free — both are text editors designed for code and will color-code your HTML to make mistakes easier to spot. Either one is worth the read if you plan to write HTML more than once.
Writing or pasting your HTML code
Type your HTML directly into the editor, or copy and paste code you found elsewhere. A minimal HTML file looks like this:
<!DOCTYPE html> <html> <head> <title>My Page</title> </head> <body> <h1>Hello World</h1> <p>This is my first web page.</p> </body> </html>
The <!DOCTYPE html> line must come first — it tells the browser this is an HTML5 file. Everything else is the structure: the <head> section holds the title and invisible information, and the <body> section holds what people actually see on the page.
Do not worry about getting it perfect. You can edit the file later. For now, just get something into the editor so you have text to save.
Saving the file with the .html extension
Go to File and click Save As. A dialog box opens asking where to save and what to name the file. Type a name like mypage.html — the .html at the end is what matters. Do not use spaces in the filename; use hyphens or underscores instead, like my-page.html or my_page.html.
On Windows in Notepad, look for a dropdown that says "Save as type" and change it from "Text Documents (.txt)" to All Files (*.*). If you leave it on Text Documents, Notepad will save your file as mypage.html.txt, which will not work. On Mac in TextEdit, the format is already set to plain text if you followed the step above, so you can just type the name and save.
Choose a folder you will remember — your Desktop or Documents folder works fine. Click Save. The file now exists on your computer as an HTML file.
Opening the file in your browser
Find the file you just saved. Right-click it and choose Open with, then select your web browser — Chrome, Firefox, Safari, or Edge. The file opens in the browser and displays as a web page, not as code.
Alternatively, open your browser first, then drag the HTML file from your folder directly into the browser window. Either way, you see your page rendered.
Editing and updating your HTML file
To change the content or code, right-click the HTML file and choose Open with, then select your text editor. Make your changes, save the file (Ctrl+S on Windows, Command+S on Mac), then switch back to the browser and refresh the page (Ctrl+R or Command+R). The browser reloads the updated file and shows your changes.
Keep both windows open side by side — your text editor on one side, your browser on the other. Edit, save, refresh, and see the result when ready. This is how most people learn HTML: change something small, save, refresh, and watch what happens.
Frequently Asked Questions
What if I save the file but it opens in Notepad instead of the browser?
The file was saved as .txt instead of .html. Right-click the file, choose Rename, and change the extension from .txt to .html. Then double-click it again — it should open in your browser this time.
Can I use Microsoft Word or Google Docs to write HTML?
No. Word and Google Docs add invisible formatting that breaks HTML. Always use a plain text editor like Notepad, TextEdit, or a code editor. If you copy code from Word into a text editor, it may still contain hidden characters that cause errors.
Do I need internet to open and view an HTML file?
No. HTML files on your computer work offline. If your HTML includes images or links to other websites, those parts need internet, but the basic page displays without it.
What is the difference between .html and .htm?
They are the same thing. Both extensions work identically. Use .html because it is more common and clearer, but .htm works if you prefer it.
Can I have multiple HTML files that link to each other?
Yes. Create separate files like index.html, about.html, and contact.html in the same folder. In your HTML code, use links like <a href="about.html">About</a> to connect them. The browser finds the other files because they are in the same folder.