How to Name HTML Files

Rules to keep in mind

HTML Code

Hamza TArkkol/Getty Images

Filenames are part of your URL—and therefore an important part of your HTML. You can name your file nearly anything you choose, but you must follow a few rules of thumb to ensure that it displays correctly.

Don't Use Special Characters

For best results, use only letters, numbers, hyphens, underscores, and periods. Any other character in a file name could prevent it from loading properly or at all.

Don't Use Spaces

Most operating systems can handle file names with spaces, but web pages can't. The space typically gets displayed with an underline, so many people assume they must type the underscore character in the address bar. Furthermore, many browsers require that a space be encoded either as a plus sign or as %20.

Start the File Name With a Letter

Although this isn't absolutely required, some programming languages give numbers special notice and might not treat a file starting with a number as you intended. The page might not display correctly or might not even load at all.

Use All Lowercase Letters

This is also not an absolute requirement, but it's a good practice. Unlike personal computer operating systems, most web server operating systems are case sensitive. This means that your Windows machine might see Filename.htm the same as filename.htm but your web server would see that as two different files. This is a common reason images fail to display on websites created by novice designers.

Keep Your Filenames Short

Although a URL could be as long as 2000 characters or so, it's best to keep filenames short and helpful. Filenames of no more than four or five words or 30 to 50 characters are ideal. File names that indicate their content or purpose can be helpful, too, especially when dealing with a large site of many pages.

Remember the File Extension

Most HTML editors add extensions automatically, but if you write your HTML in a text editor such as Notepad, you must include it yourself. You have two choices for straight HTML files: .html and .htm.

There's no functional difference between .htm and .html. Choose whichever you prefer, and use it throughout your website.

Good HTML File-Naming Practices

When naming HTML files, keep these guidelines in mind:

  • People read the URLs and links for clues as to what the page is about. A clear, understandable filename gives your visitors confidence in your site.
  • Using words separated by hyphens can help with SEO because search engines read the URLs.
  • CamelCase (mixed uppercase and lowercase letters), although popular with branding experts, can be difficult to read. Furthermore, you risk a case-sensitive file system not recognizing that filename.htm and fileName.htm are the same files.
  • Naming files based on dates or other arbitrary details makes editing difficult later on. For example, if you're looking for a file about elephants, elephants.htm is an obvious choice, whereas aa072700a.htm could be about anything at all.

Generally, good file names for web pages are easy to read and understand for both you and your visitors. They're easy to remember and make sense within the site's hierarchy. Following these guidelines will help your website do its job of communicating a message, and will help you do yours of maintaining the site.