htmlnaming-conventionsfile-extension

Should I use the .htm or .html file extension? Which one is correct?


What is the difference between the .htm and .html file extensions?

Why there are two of them?

Which is correct?


Solution

  • The short answer

    There is none. They are exactly the same.

    The long answer

    Both .htm and .html are exactly the same and will work in the same way. The choice is down to personal preference, provided you’re consistent with your file naming you won’t have a problem with either.

    Depending on the configuration of the web server, one of the file types will take precedence over the other. This should not be an issue since it’s unlikely that you’ll have both index.htm and index.html sitting in the same folder.

    We always use the shorter .htm for our file names since file extensions are typically 3 characters long.

    AND MORE ON: http://www.sightspecific.com/~mosh/WWW_FAQ/ext.html or http://www.sightspecific.com/~mosh/WWW_FAQ/ext.htm

    I think I should add this part here:
    There is one single slight difference between .htm and .html files. Consider a path in your server like: mydomain.example/myfolder. If you create an index.htm file inside that folder and you open that like this: mydomain.example/myfolder/, it will go crazy and spit out your files as it is in your server,An image describing the bug with .htm files
    but if you create an index.html file in there and open that directory in your browser, it will load that file. I tested this on my VPS and found this. Maybe you could somehow set your server to load index.htm files by default, but I guess the .html file is the default file type for browsers to open in each directory.