Dashes Vs Underscores In URLs

I used to think the choice of using dashes vs underscores to separate words in an URL was simply a matter of personal preference. Nothing more than a religious choice.

Personally, I preferred underscores because I felt dashes intruded upon the words while underscores stayed at the bottom out of the way. So much so I had originally made that the default URL scheme in Subtext for friendly URLs and was using that myself.

It wasn’t till recently that I learned this debate has already been resolved. Years ago.

I wouldn’t say resolved really. Just that, there appears to be a really good reason to choose dashes over underscores. Apparently, Google sees the dash as a word separator, while the underscore is perceived to be part of the word. Something to do with being able to search for C++ style constant variables SUCH_AS_THIS in the title of a post.

The question is, does this still apply today? Does it even matter?

To be on the safe side, I'm falling in line for now. Or rather, in dash. What are your thoughts?

Tags:

What others have said

Requesting Gravatar... Simon Cox Mar 15, 2007 6:21 PM
# re: Dashes Vs Underscores In URLs
I am glad someone else is bringing up this debate again. For me it has not been resolved because the accepted way is for programming not for the common language usage of hyphens. Google got this wrong and have not put it right yet, or have they...
Requesting Gravatar... Rob Conery Mar 15, 2007 6:38 PM
# re: Dashes Vs Underscores In URLs
Underscores are terribly hard to see at times, and more than once (when a word is underlined or part of a hyperlink) I've misspelled the URL or just missed it altogether.

Dashes, em-dashes, hyphens: it's all pretty confusing idn't it? I mean what do you do when a post title has a dash in it? Remove it only to put it back :)?


For me it has not been resolved because the accepted way is for programming not for the common language usage of hyphens


Isn't that what we're talking about?
Requesting Gravatar... Steve Harman Mar 15, 2007 6:59 PM
# re: Dashes Vs Underscores In URLs
Good thing we made that totally configurable in Subtext. It took me all of 3 seconds to change the URL construction for my blog - and 2 of those seconds were spent navigating to my site's web.config file.

Also... when did you change Subtext to add the "author" class around the comment div for the Comments.ascx control?
Requesting Gravatar... James Chan Mar 15, 2007 7:41 PM
# re: Dashes Vs Underscores In URLs
Dashes bring better readability than underscores, especially when the URLs are displayed on pages with the underline style.
Requesting Gravatar... Jay Flowers Mar 15, 2007 7:51 PM
# re: Dashes Vs Underscores In URLs
There is more on the why here:

http://www.codinghorror.com/blog/archives/000574.html
Requesting Gravatar... Jeff Atwood Mar 15, 2007 7:55 PM
# re: Dashes Vs Underscores In URLs
That's right. It's all about regex. Try a \W (word character) match and see what happens.

This_is_one_word.

This-is-multiple-words.

I also agree with the earlier comments that underscore sucks for other reasons. It's less comprehensible.
Requesting Gravatar... jayson knight Mar 15, 2007 9:12 PM
# re: Dashes Vs Underscores In URLs
Hyphens all the way here...much more readable IMO.
Requesting Gravatar... Maurice Prather Mar 15, 2007 9:33 PM
# re: Dashes Vs Underscores In URLs
Who cares?

As a human, it doesn't really matter. Yes, there are some points about readability vs. typeability vs. recognizability. As long as I can recognize the url as a url, I'm good. I can always cut/paste, click on a link, etc.

As a search engine, this should absolutely not matter. If a search engine is relying on a url to give a page relevance (even if the contribution percentage is small), then I would say that relevance calculation is broken. Content matters, not the url.
Requesting Gravatar... Dave Frank Mar 15, 2007 9:54 PM
# re: Dashes Vs Underscores In URLs
If you surf around botw:

http://botw.org/top/Health/Conditions_and_Illness/

you'll see that we use underscores for spaces in the URL. Why? because it looks nicer than %20 which spaces tend to show up as, more often than not. If you had dashes for the spaces, and then had a word with a dash in it, the system could get confused.

You can see what happens with these category names:

Wolverine-Hoosier Athletic Conference
2gether - The Series
Northeast-10 Conference
Northern Illinois-Iowa Conference
Magazines and E-zines
Magazines and E-zines
Ramstein-Miesenbach
K-12
Have Gun - Will Travel
Rehburg-Loccum
Co-Ed
Requesting Gravatar... Scott Mar 15, 2007 9:56 PM
# re: Dashes Vs Underscores In URLs
Know why I hate 'em?
C & C++ folks overused them. Quick, how many underscores in this constant. Change your font, now how many? Argh!

___EVIL_LONG_CONSTANT__
Requesting Gravatar... Haacked Mar 15, 2007 10:33 PM
# re: Dashes Vs Underscores In URLs
The dash being easier to type is a GREAT consideration.

Originally, I used Wikicasing for my URLs. Now I'm trying out dashes. It's like the fashion style. I'm wearing what's en vogue.

Tomorrow I'll use another character. Maybe the "Y"!
Requesting Gravatar... Haacked Mar 16, 2007 1:09 AM
# re: Dashes Vs Underscores In URLs
> Also... when did you change Subtext to add the "author"
> class around the comment div for the Comments.ascx
> control?

Last night.
Requesting Gravatar... German Rumm Mar 16, 2007 5:02 AM
# re: Dashes Vs Underscores In URLs
I'm using dashes. Because of Google and because it's prettier.

Underscore is not even a character. Historically, it's a type-writer "hack" - to make it easy to underline words.

Computer keyboard was copied from type-writer, and that's why we have underscore and QWERTY layout.
Requesting Gravatar... Robb Allen Mar 16, 2007 7:49 AM
# re: Dashes Vs Underscores In URLs
You can have my underscores when you pry the bits from my cold, dead, L2 cache.

Honestly, I'm agnostic, although anything that irritates Google is good for me. Google is NOT the MCP (anyone else remember Tron?) and we should not force our coding standards to make Google's life easier. Google is supposed to adapt to us, not vice versa.

That being said, dashes are easier to read, for sure.
Requesting Gravatar... Ryan Smith Mar 16, 2007 9:34 AM
# re: Dashes Vs Underscores In URLs
It's funny that Atwood brings up the point that the regular expressions are easier to write in order to parse the URLs with dashes.

I had the exact opposite problem. I would run a regular expression on my friendly URLs to make sure that there were only valid alphanumeric characters. The dash would break this so I had to rewrite my regexp.

Not that this was difficult, but I never looked at from the other point of view.
Requesting Gravatar... Tom's Blog Apr 24, 2007 5:24 AM
# Dashes Vs Underscores In URLs
Dashes Vs Underscores In URLs Dashes Vs Underscores In URLs .
Requesting Gravatar... David Huntley Jun 05, 2007 2:43 AM
# re: Dashes Vs Underscores In URLs
I'm i not correct in thinking that domains can not contain an underscore character if you want to have compatibility with IE and cookies? Surely that's reason enough to switch if you haven't.

What do you have to say?

(will show your gravatar)
Please add 2 and 6 and type the answer here: