This is a highly opinionated topic (the following video completely sums it up), so feel free to agree/disagree with me. 🙂
When working with files that eventually end up on the Web, there is an age-old debate over whether to use dashes or underscores in the place of spaces in file names. Using spaces in file names is highly discouraged, as the special character representing a space (
%20) often breaks in chats and messaging clients, creating an invalid URL, and are generally considered annoying URLs (much like spaces in file paths are in programming). So what is a good replacement character for a space? In this post, we will be briefly exploring the use of dashes, spaces, and periods as replacements for spaces in URLs. As already stated, since this topic is based on personal preference you are obviously free to choose whatever replacement you want. 🙂
In URLs, dashes are interpreted literally, meaning there is not a special character for it. So instead of a URL with spaces in it, such as
it is now
From my experience, dashes work the best, as they ar easier to type (especially on mobile keyboards) and look the nicest.
Underscores are also interpreted literally, so no special character to worry about. The same URL using underscores looks like
On both full-size and mobile keyboards, an underscore is only accessed through a modifier key, so it is a bit harder to type.
Unlike dashes and underscores, periods are actually represented by a special character,
%2E. Therefore, they are subject to the same issues as spaces, especially when they are at the end of a URL. I cannot count the number of times I have seen URLs that end with periods just to have that trailing period break the entire URL. For completeness, our example URL with periods as separators would look like
Bonus Item! Nothing
What if you use no separator? What would happen then? Nothing! With your URL like
you have none of the issues spaces create. However, for really long URLs, this can make them hard to read and get a quick idea of what it is (oh, you did not know URLs are supposed to actually give a hint of what it points to, did you?). You would probably save this one for super short URLs, like ones you get from URL shortening services. 😉