views:

4266

answers:

20
+27  Q: 

Dash vs. Underscore

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?

+3  A: 

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
+15  A: 

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.

Bill James
+4  A: 

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

RodgerB
/about/us/no/seriously/this/is/it :)
Brad Wilson
and this is your solution? Fine, what about "about_our_customers" or any of a myriad set of "abouts" I could come up with that might be relevant. Ignoring a problem != solution.
Bill James
+5  A: 

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
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
+1  A: 

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
Yeah, but that's only in hostnames.
Anirvan
+7  A: 

Jeff has some thoughts on this: http://www.codinghorror.com/blog/archives/000574.html

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

s t
+1 because it mentions how Google expects it, which I would gues is more important than how it looks.
tj111
+6  A: 

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
jpeacock
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
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.
Seriously bad advice.
Lucifer
Somebody tell Jeff he needs to rewrite the tag system...
Will
+2  A: 

Dashes for SEO and underscores for readability. Pick one!

Joe Philllips
+1  A: 

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

Krirk
A: 

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

tdyen
How would the search engine know where a word begins or ends?
Joe Philllips
Why wouldn't the search engine deal with PascalCase the same as any other delimeter, be it a _, - or : for that matter?
tdyen
Good advice... is this question was asking about code. urls are [usually] case-insensitive, and are typically shown in lowercase.
Atømix
@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
+5  A: 

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
A: 

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.

+13  A: 

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.

MrZebra
+1 interesting answer, thanks!
Marco Demajo
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'
Atømix
+3  A: 

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
+1  A: 

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).

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

Andrew Ingram
+15  A: 

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
Welcome to the Wild Wild Web!
Even Mien
+2  A: 
plindberg
+1  A: 

Having devoted considerable time to this question during my career, particularly in recent years, I can only conclude that dashes are not the best delimiter. Moreover, I believe a consensus will emerge eventually with an alternative character being used universally -- probably the underscore:-

http://www.timacheson.com/Blog/2009/aug/friendly_url_should_not_use_dashes_to_represent_spaces

Tim
A: 

Some other thing I'm curious about.

Does the suffix make a difference? HTML or HTML ?

Bruno
+3  A: 

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