230

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?

Zaffer
  • 1,290
  • 13
  • 32
lubos hasko
  • 24,752
  • 10
  • 56
  • 61
  • 6
    Why not */index____1125.aspx* (that's four underscores, very important!) – Christian Davén May 05 '11 at 08:05
  • 7
    [Duplicate question on a site where this issue is *definitely on-topic*.](http://webmasters.stackexchange.com/questions/374/urls-should-i-use-hyphens-underscores-or-plus-symbols) – Mark Amery Feb 04 '15 at 23:22
  • 4
    Good video explain from Google engineer: https://www.youtube.com/watch?v=AQcSFsQyct8 – JohnB May 21 '15 at 15:31
  • 1
    Came here to find out `whether_domain_URLs_can_have_underscores.com`. – neverMind9 Jun 17 '19 at 23:57
  • Related: https://stackoverflow.com/questions/10302179/hyphen-underscore-or-camelcase-as-word-delimiter-in-uris – Anton Tarasenko Apr 24 '20 at 10:05
  • **TL;DR**: A domain name cannot contain underscores (not allowed). The part of the url *after* the domain name *can* contain underscores, although they're not recommended (use a dash instead, as it will rank better with search engines). – stevec Oct 07 '20 at 07:28

18 Answers18

231

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.

James Lawruk
  • 30,112
  • 19
  • 130
  • 137
  • 5
    Google didn't explain why? Supposedly it has something to do with their way of parsing addresses? Or probably it's just an end-user issue. – xji Jan 15 '15 at 12:35
  • 14
    also worth noting that underscored_text is selectable as a whole by double clicking in some devices and long-pressing on mobiles, whereas with dash-separated-text the same actions select each separated word. Think about if a user would ever try to copy out something from the url – Tito Jan 08 '16 at 17:15
  • 3
    I think you might have hit a causality loop there @Titus, as that's completely contrary to actual ... English, which DOES have dashes in words, but doesn't have underscores. – billjamesdev Feb 03 '16 at 02:18
  • 1
    my guess is there is no difference, at least for google, whether there is '_', '-' or nothing. Google went with what I am assume is the most readable for humans, a dash – Arthur Tarasov Dec 14 '17 at 08:51
  • 1
    See https://youtu.be/AQcSFsQyct8 for Google's explaination. (They used "_" for exact search matching.) – Matt Ke Nov 02 '18 at 13:26
  • I can't believe that Google is so incompetent that their crawlers can't treat hyphens and underscores similarly. – endolith Jan 01 '19 at 20:10
87

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.
Ravi Ram
  • 24,078
  • 21
  • 82
  • 113
Emanuil Rusev
  • 34,563
  • 55
  • 137
  • 201
  • And a downside: dashes have specific usages in language, whereas underscore does not. Therefore, underscore can represent a space, and dashes can keep their purpose. E.g. https://en.m.wikipedia.org/wiki/Catherine_Zeta-Jones (the system works well for Wikipedia!). – rybo111 Sep 25 '22 at 23:32
  • 1
    Oh, and another upside of dash: when you're reading out a URL in English, "dash" is one syllable, whereas "underscore" is three syllables. – rybo111 Sep 26 '22 at 06:35
57

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
Mark Stock
  • 1,713
  • 2
  • 13
  • 23
  • 61
    Welcome to the Wild Wild Web! – Even Mien Nov 03 '09 at 12:07
  • 1
    I'm quite fond of slash/means/space when used elegantly. One of the sites that I run uses /about/us alongside various other /about/ pages. I don't recall seeing any more mainstream examples though. – Sekalf Nroc Apr 13 '19 at 18:30
38

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.

Zebra North
  • 11,412
  • 7
  • 37
  • 49
  • 11
    Your average semi-computer-illiterate web surfer is unlikely to be able to tell the difference between address bar and search. Your average user is also MUCH more likely to click than type. Just sayin' – Armstrongest Jul 19 '10 at 19:45
  • 2
    Google still does NOT treat underscore as a word separator: http://www.youtube.com/watch?v=AQcSFsQyct8 – Sembiance Aug 17 '11 at 13:14
31

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.

billjamesdev
  • 14,554
  • 6
  • 53
  • 76
  • 15
    Reasonable guess, but as it turns out, totally untrue. -1. – Mark Amery Feb 04 '15 at 23:29
  • 2
    Do you have a reference for that @MarkAmery? The question revolved around why Google would use underscores. If you're suggesting they don't, that's not this answer's issue, but the question's issue. – billjamesdev Feb 03 '16 at 02:20
  • 1
    First, as guesses go, pretty reasonable. I'd add as part of the guess that programmers use the dash as subtraction so underscore is used; perhaps URLs, created by programmers, follow that convention. An actual explaination would be better though. Mark escalates with a -1 without any backup; wish I could give the comment a -1. – Gerard ONeill Mar 07 '17 at 00:04
  • 1
    Thanks @GerardONeill. It's a very old response now, and probably much of what's said in this page is now less accurate and even further less relevant. – billjamesdev Mar 07 '17 at 04:10
  • 1
    @billjamesdev -- Yeah I know; it was relevant to me in 2017, but didn't realize I was replying to a post from 2008! I was still just looking for a comment that made sense. Mark's comment also got me uppity. – Gerard ONeill Mar 07 '17 at 15:16
  • 2
    @GerardONeill citation: this video by Google Webmasters: https://www.youtube.com/watch?v=AQcSFsQyct8. Per that video (admittedly now 6 years old and possibly not representing the contemporary status quo), `foo_bar` is treated as a single word while `foo-bar` is treated as two words - precisely the opposite of what this answer speculates is the case. – Mark Amery Dec 19 '17 at 21:49
  • 3
    @MarkAmery I hear what you're saying, and you're really just relaying others' words from a while ago, but doesn't it jar you to hear that "foo_bar" is treated as a word, when it quite literally can't be one (as there are no words with underscores). Whereas "self-esteem" is a perfectly valid compound word in English, and ought to be searchable as a single entity? – billjamesdev Dec 19 '17 at 22:51
  • @MarkAmery Thanks for the vid! I must have been off my meds (figure of speech-wise) when I was commenting; thanks for being accommodating. – Gerard ONeill Dec 20 '17 at 10:30
  • @MarkAmery And since when define Google Webmasters anything on this planet? English grammar rules are older than Google and dashes are in fact hyphens and create "compounded words", that is they make two words become one word, as in pizza-lover, which is to be treated as a single word and not as two words next to each other. Yet there are no rules for underscore which has been used a space replacement as long as computers exist and pizza_lover are two words and no compound. – Mecki Jan 04 '22 at 01:03
16

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.

seanb
  • 6,969
  • 2
  • 33
  • 34
13

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.

deppfx
  • 701
  • 1
  • 10
  • 24
s d
  • 2,666
  • 4
  • 26
  • 42
  • +1 because it mentions how Google expects it, which I would gues is more important than how it looks. – TJ L Jul 10 '09 at 19:53
9

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.

Devin Jeanpierre
  • 92,913
  • 4
  • 55
  • 79
  • 2
    Just a side note, languages like Lisp or Scheme customary use variable/function names separated with dashes, because minus is just an identifier of function just like any other (and in fact, they allow larger character set in identifiers). – J S Nov 16 '09 at 08:58
  • The article [Dashes vs. Underscores in URLs](https://writing.fletom.com/dashes_vs_underscores_in_URLs) makes similar points; it also references more specific examples of dash vs. underscore in [Hyphen - Varied meanings - Wikipedia](https://en.wikipedia.org/wiki/Hyphen#Varied_meanings). – davidvandebunte Sep 10 '22 at 20:35
8

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.

Christian Davén
  • 16,713
  • 12
  • 64
  • 77
5

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
Jason Peacock
  • 1,783
  • 11
  • 17
  • 40
    I've got to disagree with this. These days it's customary to just use dashes. Non programmers find the underscores visually unattractive. Nothing wrong with the first example. It's actually more friendly to read. – allesklar Jul 11 '09 at 08:14
  • 9
    Semantically you're right, but the distinction might be more confusing than useful for usage in URL's. People are more likely to remember "a-b-c-d-e" than "a-b_c-d_e". – Wadih M. Sep 13 '09 at 04:14
  • Somebody tell Jeff he needs to rewrite the tag system... –  Jul 19 '10 at 21:15
  • 1
    Really? @Wadih, if people are spelling words correctly, there's nothing hard to remember about low-budget_movies. You don't have to remember it any more than the words "low-budget movies". Of course when you just use a, b, c, d, e, then it makes no sense. "Low-budget" is *not* the same as "low budget", period. – fletom Sep 04 '11 at 16:04
  • bad: /low-budget-movies, bad: /low-budget_movies, good: /low-budget%20movies – Mikhail Antonov Mar 19 '19 at 05:36
3

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

Geoff
  • 3,749
  • 2
  • 28
  • 24
3

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.

Aberrant
  • 3,423
  • 1
  • 27
  • 38
Andrew Ingram
  • 5,160
  • 2
  • 25
  • 37
2

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

Krirk
  • 1,466
  • 2
  • 10
  • 10
0

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

RodgerB
  • 8,608
  • 9
  • 36
  • 47
0

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

Jon Limjap
  • 94,284
  • 15
  • 101
  • 152
  • 2
    Yeah, but that's only in hostnames. – Anirvan Mar 03 '09 at 16:53
  • Wrong. All DNS servers have issues with underscore as underscore is no legal character in domain names; period. Check the standards if you don't belief me. But DNS servers only parse the host part of an URL and nothing else and this question was not about host part or DNS names. – Mecki Jan 04 '22 at 01:06
0

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

  • How would the search engine know where a word begins or ends? – Joe Phillips Feb 12 '10 at 02:05
  • Why wouldn't the search engine deal with PascalCase the same as any other delimeter, be it a _, - or : for that matter? –  Feb 15 '10 at 04:38
  • 1
    Good advice... is this question was asking about code. urls are [usually] case-insensitive, and are typically shown in lowercase. – Armstrongest Jul 19 '10 at 19:50
  • 1
    @dI-_-Ib Only the domain names are case-insensitive. The path is case-sensitive, making the camel and pascal styles a viable option. Although, by using them you are effectively making the words they represent case-insensitive. That would be the biggest issue with that option, in my opinion. – Atli Jul 30 '10 at 14:29
0

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.

0

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

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

Eddy Freddy
  • 1,820
  • 1
  • 13
  • 18