File Naming Conventions for Web Developers

Joseph Pinder | | 2 min read

Whenever I mention naming conventions to my students for the first time, there’s just a slight confusion that seems to fill their minds.

Naming conventions are helpful tools for organizing and structuring directories (or folders) and files. In web development, this includes filenames, directory names, and project structures.

For the purposes of this article, we’ll just focus on best practices when naming directories and files.

What are naming conventions?

According to Wikipedia, “a naming convention is a convention (generally agreed scheme) for naming things.”

That seems right.

More succinctly, a naming convention is an agreed way of naming things.

This agreement can be with yourself, as part of a team, or come from broader sources like best practices in your industry.

Naming Directories And Files

When it comes to naming directories and files, there are a few rules that we need to follow.

  • Lowercase Only – When naming directories and files, ensure that all names are lowercase only.
  • Alphanumerics and Limited Special Characters – Only use alphanumerics when naming directories and files. Alphanumerics are the characters a-z and 0-9. The only exceptions to this rule are - (hyphens), _ (underscores), and ~ (tildes).
  • No Spaces – Don’t use spaces in directory or file names. Spaces are encoded by the server (e.g., %20 in URLs), producing long, ugly URLs. Use hyphens instead.
  • Keep It Short – Names should always be descriptive, but when possible, try to keep directory and file names short. In most instances, around 25 characters or less is a good guideline.
  • Proper File Extensions – Whether it’s index.html, style.css, script.js, or any other file, make sure that the file extension is properly separated from the filename with a period (.).
  • Be Consistent – In all of this, be consistent. Consistency ensures an organized directory and file structure that makes everything easier to find.

Final Thoughts

Naming your files and directories the right way might seem like a small thing, but it makes a huge difference in the long run. A clean and consistent file structure keeps things organized, makes collaboration easier, and helps you avoid unnecessary headaches down the road.

Think of it like keeping your workspace tidy—when everything has a proper place, you can find what you need quickly, work more efficiently, and spend less time fixing avoidable mistakes.

Resources