What an HTML file is and why you might need one
An HTML file is a plain text document that tells a web browser how to display a webpage. It contains instructions written in a language called HTML (HyperText Markup Language) that format text, add images, create links, and build the structure of what you see on screen. When you open a webpage in Chrome, Firefox, Safari, or Edge, you are looking at an HTML file that the browser has read and turned into the page you see.
You might need to create an HTML file if you want to build a simple webpage, save a document in a format that browsers can read, or learn how web pages work. The good news is that creating one requires only a text editor — the same program you use to write notes — and takes just a few minutes.
Key Takeaways
- HTML files are plain text documents that you create in Notepad (Windows), TextEdit (Mac), or any text editor, then save with the .html file extension.
- You must save the file as plain text, not as a formatted document, or the browser will not read it correctly.
- After saving, you can open the HTML file in any web browser by double-clicking it or dragging it into the browser window.
- The simplest HTML file needs only a few lines of code: opening and closing tags that tell the browser what content goes where.
Creating your first HTML file on Windows
Open Notepad, which comes built into every Windows computer. Click the Start button, type "Notepad" into the search box, and press Enter. A blank text window will open.
Type or paste your HTML code into the window. The simplest working example looks like this:
<html> <head> <title>My First Page</title> </head> <body> <h1>Hello World</h1> <p>This is my first webpage.</p> </body> </html>
Once you have typed or pasted the code, click File in the top left, then click Save As. A dialog box will open asking where you want to save the file and what to name it. Type a name for your file — for example, "mypage" — then type .html at the end. The full filename should look like "mypage.html". Make sure the file type dropdown at the bottom says "All Files" and not "Text Documents", or Windows will add .txt to the end and the browser will not read it. Click Save.
Creating your first HTML file on Mac
Open TextEdit, which is in your Applications folder. Click Finder, then Applications, then double-click TextEdit. A blank document will open.
Before you type anything, you must change TextEdit to plain text mode. Click Format in the top menu, then click "Make Plain Text". This step is essential — if you skip it, TextEdit will add formatting codes that break the HTML file.
Now type or paste your HTML code (the same example shown above works here too). Click File in the top menu, then click Save. A dialog box will open. Type your filename with .html at the end — for example, "mypage.html". Choose where you want to save it, then click Save. If TextEdit asks whether you want to use the .html extension, click "Use .html".
Understanding the basic structure of HTML
Every HTML file follows the same basic structure, even though the content inside changes. The opening tag <html> tells the browser "this is an HTML file." The closing tag </html> at the end tells the browser "the HTML file ends here." Everything in between belongs to the file.
Inside the <html> tags, you have two main sections. The <head> section contains information about the page that the browser needs but the visitor does not see — like the title that appears in the browser tab. The <body> section contains everything the visitor sees on the page: text, images, links, and other content. The <h1> tag creates a large heading, and the <p> tag creates a paragraph of regular text.
You do not need to understand every tag to create a working file. You can copy the basic structure above, change the title and the text inside the <body> tags, and save it as a new HTML file. The browser will read it correctly.
Opening your HTML file in a web browser
Once you have saved your HTML file, you can view it in a web browser. The simplest way is to find the file on your computer, then double-click it. Your default browser (usually Chrome, Firefox, Safari, or Edge) will open and display the page.
If double-clicking does not work, or if you want to open the file in a different browser, right-click the HTML file (or Control-click on Mac), then look for "Open With" in the menu. Select the browser you want to use. The page will open in that browser, and you will see your HTML code displayed as a webpage.
If you make changes to the HTML file later, save the changes in your text editor, then refresh the browser window (usually by pressing Ctrl+R on Windows or Command+R on Mac). The browser will read the updated file and show the new version.
Common mistakes that break HTML files
The most common mistake is saving the file as a formatted document instead of plain text. If you use Microsoft Word or Google Docs, those programs add hidden formatting codes that break HTML. Always use Notepad, TextEdit (in plain text mode), or another plain text editor.
The second mistake is forgetting the .html extension when you save. If your file is named "mypage" instead of "mypage.html", the browser may not recognize it as a webpage. Check the filename in your file manager to make sure it ends with .html.
The third mistake is mismatched or missing closing tags. Every opening tag like <p> needs a closing tag like </p>. If you open a tag and forget to close it, the browser may display the page incorrectly or not at all. When you are starting out, count your opening and closing tags to make sure they match.
Editing and improving your HTML file
Once you have created a basic HTML file, you can add more content and formatting. Open the file in your text editor (right-click it, select "Open With", then choose Notepad or TextEdit). Make your changes, then save the file. Refresh your browser to see the updates.
Common additions include links (using the <a> tag), images (using the <img> tag), lists (using <ul> and <li> tags), and bold or italic text (using <strong> and <em> tags). You can learn what each tag does by searching online for "HTML tags" or "HTML tutorial". Many websites show examples of code and what it produces in the browser.
Frequently Asked Questions
Can I create an HTML file on my phone or tablet?
Yes, but it is more difficult than on a computer. You need a text editor app that saves files as plain text — most note-taking apps add formatting. Search your app store for "text editor" or "code editor". Some options include Jotterpad (Android) or Textastic (iPad). Save the file with .html at the end, then open it in your mobile browser.
What if my HTML file opens as code instead of as a webpage?
This usually means the file does not have the .html extension. Check the filename in your file manager. If it says "mypage.txt" or just "mypage", rename it to "mypage.html". Right-click the file, select Rename, and add the .html extension. Then double-click it again to open it in your browser.
Do I need special software to create HTML files?
No. Notepad and TextEdit are free and built into Windows and Mac. You do not need to buy anything. As you get more comfortable, you might try free code editors like Visual Studio Code or Sublime Text, which highlight HTML code in different colors to make it easier to read, but they are not necessary to start.
Can I use HTML to create a real website that other people can visit?
HTML files on your computer are only visible to you. To make a website that others can visit, you need to upload your HTML file to a web server, which is a computer that stays on all the time and is connected to the internet. Many hosting companies offer this service. For now, creating and viewing HTML files on your own computer is a good way to learn how webpages work.