URLs: Dash vs. Underscore

UrlSeoNaming Conventions

Url Problem Overview


Is it better convention to use hyphens or underscores in your URLs?

Should it be /about_us or /about-us?

From usability point of view, I personally think /about-us is much better for end-user yet Google and most other websites (and javascript frameworks) use underscore naming pattern. Is it just matter of style? Are there any compatibility issues with dashes?

Url Solutions


Solution 1 - Url

From Google Webmaster Central

> Consider using punctuation in your > URLs. The URL > http://www.example.com/green-dress.html > is much more useful to us than > http://www.example.com/greendress.html. > We recommend that you use hyphens (-) > instead of underscores (_) in your > URLs.

Solution 2 - Url

Here are a few points in favor of the dashes:

  • Dashes are recommended by Google over underscores (source).

  • Dashes are more familiar to the end user.

  • Dashes are easier to write on a standard keyboard (no need to Shift).

  • Dashes don't hide behind underlines.

  • Dashes feel more native in the context of URLs as they are allowed in domain names.

Solution 3 - Url

It's not just dash vs. underscore:

  • text with spaces
  • textwithoutspaces
  • encoded%20spaces%20in%20URL
  • underscore_means_space
  • dash-means-space
  • plus+means+space
  • camelCase
  • PascalCase
  • " quoted text with spaces" (and single quote vs. double quote)
  • slash/means/space
  • dot.means.space

Solution 4 - Url

Google did not treat underscore as a word separator in the past, which I thought was pretty crazy, but apparently it does now. Because of this history, dashes are preferred. Even though underscores are now permissible from an SEO point of view, I still think that dashes are best.

One benefit is that your average semi-computer-illiterate web surfer is much more likely to be able to type a dash on the keyboard, they may not even know what the underscore is.

Solution 5 - Url

This is just a guess, but it seems they picked the one that people most probably wouldn't use in a name. This way you can have a name that includes a hyphenated word, and still use the underbar as a word delimiter, e.g. UseTwo-wayLinks could be converted to use_two-way_links.

In your example, /about-us would be a directory named the hyphenated word "about-us" (if such a word existed, and /about_us would be a directory named the two-word phrase "about us" converted to a single string of non-white characters.

Solution 6 - Url

I used to use underscores all the time, now I only use them for parts of a web site that I don't want anyone to directly link, js files, css, ... etc.

From an SEO point of view, dashes seem to be the preferred way of handling it, for a detailed explanation, from the horses mouth <http://www.mattcutts.com/blog/dashes-vs-underscores/>;.

The other problem that seems to occur, more with the general public than programmers, is that when a hyperlink with underscores is underlined, you can't see the underscore. Advanced users will work it out, but Joe Public probably won't.

Still use underscores in code in preference to dashes though - programmers understand them, most other people don't.

Solution 7 - Url

Jeff has some thoughts on this: https://blog.codinghorror.com/of-spaces-underscores-and-dashes/

There are drawbacks to both. I would suggest that you pick one and be consistent.

Solution 8 - Url

I'm more comfortable with underscores. First of all, they match in with my regular programming experience of variable_names_are_not-subtraction, second of all, and I believe this was mentioned already, words can have hyphens, but they do not ever have underscores. To pick a really stupid example, "Nation-state country" is different from "nation state country". The former translates something like "the land of nation-states" (think "this here is gun country! Best move along, y'hear?"), whereas the latter looks like a list of sometime-synonyms. http://example.com/nation-state-country/ doesn't appear to mean the same as http://example.com/nation-state_country/, and yet, if hyphens are delimiters/"space"s in addition to characters in words, it can. The latter seems more clear as to the actual purpose, whereas the former looks more like that list, if anything.

Solution 9 - Url

The SEO guru Jim Westergren tested this back in 2005 from a strict SEO perspective and came to the conclusion that + (plus) was actually the best word delimiter. However, this doesn't seem reasonable and may be due to a bug in the search engines' algorithms. He recommends - (dash) for both readability and SEO.

Solution 10 - Url

Underscores replace spaces where whitespace is not allowed. Dashes (hyphens) can be part of a word, thus joining words with hyphens that already include hyphens is ugly/confusing.

Bad:

/low-budget-movies

Good:

/low-budget_movies

Solution 11 - Url

I think dash is better from a user perspective and it will not interfere with SEO.

Not sure where or why the underscore convention started.

A little more knowledgeable debate

Solution 12 - Url

I prefer dashes on the basis that an underscore might be obscured to an extent by a link underline. Textual URLs are primarily for being recognised at a glance rather than being grammatically correct so the argument for preserving dashes for use in hyphenated words is limited.

Where the accuracy of a textual URL is important is when reading it out to someone, in which case you don't want to confuse an underscore for a space (or vice-versa).

I also find dashes more aesthetically pleasing, if that counts for anything.

Solution 13 - Url

For end-user view i prefer "about-us" or "about us" not "about_us"

Solution 14 - Url

Personally, I'd avoid using about-us or about_us, and just use about.

Solution 15 - Url

Some older web hosting and DNS servers actually have problems parsing underscores for URLs, so that may play a part in conventions like these.

Solution 16 - Url

I personally would avoid all dashes and underscores and opt for camelCase or PascalCase if its in code.

The Wikipedia article on camelCase explains a bit of the reasoning behind it's origins. They amount to

  1. Lazy programmers who didn't like reaching for the _ key
  2. Potential confusion about readability
  3. The "Alto" keyboard at xerox PARC that had no underscore key.

If the user is to see the string then I'd do none of the above and use "About us." or "AboutUs" if I had to as camelCase has spread to common usage in some areas such as product names. i.e ThinkPad, TiVo

Solution 17 - Url

Spaces are allowed in URL's, so you can just use "/about us" in a link (although that will be encoded to "/about%20us". But be honest, this will always be personal preference, so there is no real answer to be given here.

I would go with the convention that dashes can appear in words, so spaces should be converted to underscores.

Solution 18 - Url

Better use . - / as separators, because _ seems not to be a separator.

http://www.sistrix.com/blog/832-how-long-may-a-linktext-be.html

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionlubos haskoView Question on Stackoverflow
Solution 1 - UrlJames LawrukView Answer on Stackoverflow
Solution 2 - UrlEmanuil RusevView Answer on Stackoverflow
Solution 3 - UrlMark StockView Answer on Stackoverflow
Solution 4 - UrlMrZebraView Answer on Stackoverflow
Solution 5 - UrlbilljamesdevView Answer on Stackoverflow
Solution 6 - UrlseanbView Answer on Stackoverflow
Solution 7 - Urls dView Answer on Stackoverflow
Solution 8 - UrlDevin JeanpierreView Answer on Stackoverflow
Solution 9 - UrlChristian DavénView Answer on Stackoverflow
Solution 10 - UrlJason PeacockView Answer on Stackoverflow
Solution 11 - UrlGeoffView Answer on Stackoverflow
Solution 12 - UrlAndrew IngramView Answer on Stackoverflow
Solution 13 - UrlKrirkView Answer on Stackoverflow
Solution 14 - UrlRodgerBView Answer on Stackoverflow
Solution 15 - UrlJon LimjapView Answer on Stackoverflow
Solution 16 - Urluser18443View Answer on Stackoverflow
Solution 17 - UrlpbeanView Answer on Stackoverflow
Solution 18 - UrlEddy FreddyView Answer on Stackoverflow