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 webpage. It contains tags — instructions wrapped in angle brackets — that format text, add images, create links, and organize content. You can create one with any text editor on your computer, save it with a .html extension, and open it in a browser to see how it looks.
People make HTML files for many reasons: to build a personal website, create a local document that displays formatted content without needing internet, learn web development, or store information in a format that any browser can read. Unlike a Word document or PDF, an HTML file is portable and works the same way on Windows, Mac, or Linux.
Key Takeaways
- You create an HTML file by typing code into a plain text editor like Notepad (Windows) or TextEdit (Mac), then saving it with a .html or .htm extension instead of .txt.
- The simplest HTML file needs only a basic structure: opening and closing tags that tell the browser where the content begins and ends.
- You open and view your HTML file by dragging it into a web browser or right-clicking and selecting "Open With" and choosing your browser.
- If your file does not display correctly, check that you saved it as plain text (not rich text) and that the file extension is .html, not .txt.
Creating an HTML file on Windows
Open Notepad by pressing the Windows key, typing "Notepad", and pressing Enter. You can also right-click on your desktop, select "New", then "Text Document". Type or paste your HTML code into the blank window. A minimal working example 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 you have typed your content, go to File and click "Save As". In the dialog box, type a filename followed by .html — for example, "mypage.html". Make sure the "Save as type" dropdown is set to "All Files" rather than "Text Documents (.txt)". Choose where you want to save it (your Desktop or Documents folder works fine) and click Save.
Creating an HTML file on Mac
Open TextEdit by pressing Command + Space, typing "TextEdit", and pressing Enter. Go to Format menu and select "Make Plain Text" — this is essential, because TextEdit defaults to rich text format, which will break your HTML file. Then type or paste your HTML code into the window.
Go to File and click "Save". Type your filename with a .html extension — for example, "mypage.html". TextEdit will ask whether you want to use the .html extension; click "Use .html". Choose a location to save (Desktop or Documents) and click Save. If TextEdit asks about using an extension other than .txt, confirm that you want to use .html.
Opening and viewing your HTML file
Once saved, locate your file in File Explorer (Windows) or Finder (Mac). Double-click it, and it will open in your default web browser. If it opens in a text editor instead, right-click the file, select "Open With", and choose a browser like Chrome, Firefox, Safari, or Edge.
The browser will read your HTML tags and display the formatted page. If something looks wrong — text is not formatted the way you expected, or the page is blank — go back to your text editor, check your code for typos or missing closing tags, save the file again, and refresh the browser (press F5 or Ctrl+R on Windows; Command+R on Mac).
Common mistakes and how to fix them
The most frequent problem is saving the file as .txt instead of .html. Check the filename in File Explorer or Finder; it should end with .html. If it shows .txt, right-click the file, select "Rename", and change the extension to .html.
Another common issue is saving in rich text format instead of plain text. On Mac, always use "Make Plain Text" before typing. On Windows, Notepad saves as plain text by default, but if you use Word or another editor, go to File > Save As and choose "Plain Text" or "All Files" from the dropdown. If your HTML displays as code instead of formatted content, the browser is reading it as text rather than interpreting the tags — this usually means the file extension is wrong or the file was not saved as plain text.
Where to save your HTML file and how to organize it
You can save an HTML file anywhere on your computer — Desktop, Documents, or a dedicated folder. If you plan to add images or other files to your webpage, create a folder for your project and keep the HTML file and all related files inside it. For example, create a folder called "My Website", put your HTML file inside, and create a subfolder called "images" for any pictures you want to display.
When you link to images or other files in your HTML code, use relative paths — paths that describe where the file is relative to your HTML file. If an image is in an "images" subfolder, you would write <img src="images/photo.jpg"> instead of typing the full computer path. This keeps your project portable; you can move the entire folder to another computer and all the links will still work.
Next steps after creating your first HTML file
Once you have created and viewed a basic HTML file, you can expand it by learning more HTML tags. Common tags include <h1> through <h6> for headings, <p> for paragraphs, <a> for links, <img> for images, and <ul> or <ol> for lists. Each tag has an opening version (like <p>) and a closing version (like </p>).
If you want to style your page with colors, fonts, and layouts, you can add CSS (Cascading Style Sheets) inside a <style> tag in the head section, or link to an external CSS file. Many free resources online show examples of HTML and CSS code you can copy and modify for your own use.
Frequently Asked Questions
What is the difference between .html and .htm?
Both extensions work identically. .html is more common on modern systems, while .htm is a legacy extension from older operating systems that limited filenames to three-character extensions. Use .html unless you have a specific reason not to.
Can I create an HTML file on my phone or tablet?
Yes, but it is more difficult. You need a text editor app that saves as plain text — most note-taking apps add formatting. Search your app store for "text editor" or "code editor" and look for one that explicitly supports plain text and lets you choose file extensions. Desktop computers are easier for this task.
Do I need internet to view my HTML file?
No. Once saved on your computer, you can open and view it in a browser without any internet connection. If your HTML file contains links to external websites or images hosted online, those links will not work offline, but the file itself and any local images will display fine.
What if my HTML file opens as code instead of a formatted page?
The browser is treating it as text rather than HTML. Check that the filename ends with .html (not .txt). If the extension is correct, try right-clicking the file, selecting "Open With", and choosing a different browser. If it still shows code, the file may have been saved in rich text format; open it in your text editor, go to File > Save As, and resave it as plain text with a .html extension.
Can I edit my HTML file after I create it?
Yes. Right-click the file and select "Open With", then choose your text editor. Make your changes, save the file, and refresh your browser to see the updates. You can edit and resave as many times as you want.