Imagine you're learning HTML for the first time. You open a text editor, write your first HTML document, and save it as index.html.
Everything works perfectly. The browser opens your file and displays the webpage.
A few days later, you download an HTML example from the internet. But this time, the filename is index.htm instead of index.html.
Now you might wonder: Why is this file using a different extension? Is .htm an older version of HTML? Does it support fewer features? And more importantly, which extension should you use when creating your own webpages?
The good news is that both `.html` and `.htm` represent HTML documents, and modern browsers treat them the same way.
However, there's an interesting historical reason why we ended up with two extensions for the same type of file.
What Is a File Extension?
Before understanding the difference between .html and .htm, let's first understand what a file extension is.
A file extension is the part of a filename that usually appears after the final dot (.). It helps operating systems, applications, and users identify the type of content a file is expected to contain.
For example, consider these filenames:
photo.jpg— An image filedocument.pdf— A PDF documentscript.js— A JavaScript filestyle.css— A CSS stylesheetindex.html— An HTML document
In index.html, the filename is index, and the extension is .html.
The extension helps your operating system determine which application should open the file by default. For example, double-clicking an .html file will typically open it in your default web browser.
However, a file extension does not determine the actual contents of a file. You could rename a plain text file from .txt to .html, but that wouldn't automatically turn its contents into valid HTML.
Similarly, browsers do not rely exclusively on file extensions to identify web content. When an HTML document is delivered over HTTP, the server normally identifies its content type using a header such as:
Content-Type: text/html
This tells the browser that the response contains HTML.
What Are .html and .htm Files?
Both .html and .htm are filename extensions commonly used for documents written in HTML (HyperText Markup Language).
HTML is the markup language used to define the structure and content of webpages. It allows developers to create headings, paragraphs, links, images, tables, forms, and other elements.
Consider the following HTML document:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My First Webpage</title>
</head>
<body>
<h1>Hello, World!</h1>
<p>This is my first HTML document.</p>
</body>
</html>You can save this document using either of these filenames:
index.html
or
index.htm
If you open either file in a modern browser, you'll see the same result:
Hello, World!
This is my first HTML document.
There is no difference in how the browser interprets the HTML markup simply because you changed the extension.
The HTML elements, attributes, JavaScript, CSS, and other supported browser features work the same way in both files.
So, if both extensions work exactly the same, why do we have two of them?
Why Do We Have Two HTML File Extensions?
The reason goes back to the early days of personal computers, particularly the limitations of older operating systems and filesystems.
Today, we're used to filenames such as:
my-first-html-tutorial.html
We can use long filenames and extensions containing several characters without thinking about it.
But that wasn't always possible.
The Old 8.3 Filename Limitation
Early DOS systems commonly used a filename format known as 8.3.
Under this convention, filenames could contain a maximum of eight characters before the dot and three characters after it.
For example:
FILENAME.TXTHere, FILENAME contains eight characters, while TXT contains three.
Other examples include:
REPORT.DOC
PHOTO.JPG
INDEX.HTMThe problem was that the extension .html contains four characters.
Under the traditional 8.3 filename format, a four-character extension couldn't be used.
To work around this limitation, developers used .htm, which contains only three characters.
For example:
INDEX.HTM ✓ Supported
INDEX.HTML ✗ Not supported under 8.3 naming rulesThis is the main historical reason .htm became popular.
It wasn't created as a different HTML format. It was simply a shorter extension that worked within the filename restrictions of older systems.
What Changed Later?
As operating systems and filesystems evolved, support for longer filenames became widely available.
Windows 95, for example, introduced long filename support to mainstream Windows users, allowing filenames and extensions that weren't limited to the traditional 8.3 format.
Other operating systems, including Unix-based systems, already supported more flexible filenames.
Once longer extensions became practical, developers could use .html without worrying about the old three-character restriction.
However, .htm didn't disappear.
By that point, many websites, development tools, and existing files were already using it. There was no technical reason to stop supporting the shorter extension.
As a result, both .html and .htm continued to be used.
Even today, you may occasionally encounter .htm files in older websites, documentation, or applications.
Is There Any Technical Difference Between .html and .htm?
For normal HTML documents, there is no difference in the HTML features supported by the two extensions.
An HTML document saved with .htm can contain the same elements and attributes as a document saved with .html.
For example, the following code works in either file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HTML Example</title>
</head>
<body>
<h1>Welcome to My Website</h1>
<button onclick="showMessage()">
Click Me
</button>
<script>
function showMessage() {
alert("Hello from JavaScript!");
}
</script>
</body>
</html>Whether you save this as example.html or example.htm, the browser can display the heading and execute the JavaScript when you click the button.
You can also use CSS, forms, images, semantic HTML elements, and other modern browser features in both files.
One important distinction is that the filename extension itself doesn't determine the version of HTML being used.
For example, .htm does not mean HTML 4, and .html does not automatically mean modern HTML.
The browser interprets the document based on its content and the rules of HTML parsing, not the number of characters in its extension.
Which Extension Should You Use?
For new HTML projects, I recommend using `.html`.
It's the more common and recognizable choice in modern web development. Most beginner tutorials, code examples, frameworks, and project templates use .html for HTML documents.
For example, a typical project might look like this:
my-website/
│
├── index.html
├── about.html
├── contact.html
│
├── css/
│ └── style.css
│
├── js/
│ └── script.js
│
└── images/
└── logo.pngUsing .html consistently makes the project easier to understand, particularly when working with other developers.
However, this doesn't mean .htm is wrong or outdated in terms of browser support.
If you're working on an existing project that uses .htm, there's usually no need to rename every file just to use .html.
Both extensions are valid choices for HTML documents.
The important thing is to be consistent within your project and follow any naming conventions required by the tools or hosting environment you're using.
Does the File Extension Matter to Web Servers?
This is where things become slightly more interesting.
Although browsers can render both extensions identically, web servers and hosting platforms may have their own rules for handling filenames.
For example, when someone visits:
https://example.com/the server may automatically look for a default document such as:
index.htmlThis behavior depends on the server's configuration.
Some servers are configured to recognize both index.html and index.htm, while others may recognize only certain filenames by default.
Similarly, a web server may use file extensions to determine which MIME type to send in its HTTP response.
Both .html and .htm are commonly associated with:
Content-Type: text/htmlHowever, the actual behavior depends on the server configuration.
It's also worth remembering that URLs don't always correspond directly to physical files.
For example, in an ASP.NET Core MVC application, a URL such as:
https://example.com/productsmay be handled by a controller action rather than a physical products.html file.
In such applications, routing and server-side rendering determine how the response is generated.
The absence of .html or .htm in the URL doesn't mean the browser isn't receiving HTML.
What Happens If You Save HTML with a .txt Extension?
Let's try a small experiment.
Create a new file containing this HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Testing File Extensions</title>
</head>
<body>
<h1>Hello, HTML!</h1>
</body>
</html>Now save it as:
example.txt
If you open this file in a text editor, you'll see the HTML source code.
If you open it directly in a browser, the browser may treat it as plain text rather than rendering it as a webpage.
Now rename the same file to:
example.html
Open it again in your browser.
This time, the browser will normally recognize it as an HTML document and display the heading:
Hello, HTML!
The contents of the file haven't changed. Only the extension has changed.
This demonstrates how file extensions can influence the way applications identify and handle files.
However, remember that the extension is not the only factor. When content is delivered by a web server, HTTP headers and browser content-handling rules also matter.
What About .xhtml?
While learning HTML, you may also come across another extension: .xhtml.
Unlike .html and .htm, .xhtml can indicate a different way of processing a document.
XHTML stands for Extensible HyperText Markup Language. It uses XML syntax rules, which are stricter than ordinary HTML syntax.
For example, XML requires elements to be properly nested and attribute values to be quoted.
Consider this ordinary HTML:
<input type="text" disabled>This is valid HTML.
In XHTML written using XML syntax, the equivalent would be:
<input type="text" disabled="disabled" />The important difference is not simply the filename. XHTML documents served as application/xhtml+xml are processed using XML parsing rules, while ordinary HTML documents served as text/html use HTML parsing rules.
For beginners building normal websites, there's usually no reason to use XHTML. The standard .html extension is the appropriate choice.
Final Thoughts
The existence of .html and .htm is a small reminder of how much computing has changed over the years.
The shorter .htm extension became popular because older systems commonly restricted file extensions to three characters. When those restrictions were no longer an issue, .html became a natural choice, but the older extension continued to be supported.
Today, both extensions work equally well for ordinary HTML documents.
If you're creating a new website or learning HTML, use `.html`. It's widely recognized, easy to understand, and consistent with most modern examples and tools.
If you come across a file ending in .htm, there's no need to worry. It's still an HTML document, and your browser can handle it just like a .html file.
The difference is in the filename, not in what HTML can do.
Practice Questions
1. What is the main difference between `.html` and `.htm`?
There is no difference in the HTML features supported by these extensions. Both are used for HTML documents. The shorter .htm extension became popular because older systems commonly limited filename extensions to three characters.
2. Why couldn't older DOS systems commonly use `.html`?
Traditional DOS filenames followed the 8.3 naming convention, which allowed up to eight characters for the filename and three characters for the extension. Since .html contains four characters, developers used .htm instead.
3. Which extension should you use when creating a new HTML project?
Use .html. It's the more common choice in modern web development and is widely used in tutorials, templates, and development tools.
4. Will changing a file from `.htm` to `.html` affect its HTML functionality?
Normally, no. The HTML code will behave the same way. However, you may need to update links, server configurations, or redirects that refer to the old filename.
5. Does `.htm` represent an older version of HTML?
No. Both .htm and .html can contain modern HTML. The extension does not determine which HTML features the browser supports.
6. Are `.html` and `.xhtml` the same?
Not necessarily. Ordinary HTML is parsed using HTML rules, while XHTML served with an XML MIME type is parsed using stricter XML rules. The content type and document syntax are more important than the extension alone.