I’m talking about anywhere you need to write multiple words, but can’t use spaces. For example: CSS classes and id’s, programming language variables and function names, website usernames or passwords, etc.
You can vote in the poll in the sidebar. Feel free to share your reasoning in the comments. Results in a monthish.
as an ex programmer, I was always a camelcase guy.. but in the last six months or so citing readability as a my reason i’ve migrated to hyphens. Underscores are simply an irritation to type repeatedly and quickly while coding.
if (html || css) hypens;
else camelCase;
I was always told it was bad form to use uppercase with html and css, has this changed?
I can’t answer your question but I’m also onboard with your paradigm:
* html & css – hyphens
* everything else – camel
Indeed. for html/css it should be hyphens, for php functions & else, camelCase is the best choice.
Jep, that’s the way (ah ah) I like it too.
Same here.
And, if java lower camelCase, if C# upper CamelCase
same again from me!
Same here!
It is not bad form to use uppercase with css. XHTML does not allow a mixture of upper and lower case but class names are not “html” they are classes, and css.
Not that I disagree with your choice but there is nothing wrong with camelCase for css.
Yeah, agree’d I should have specified CSS in my comment there, naturally assumed :D
although, I do sometimes use hyphens in php, however I wouldn’t entertain using hyphens in java or c++..
I think thats purely been influenced by other coders on the web, take word press functions for instance.
Personally I was taught camelCase for programming applications.
mixing my hyphens and underscores there.. lol
underscores is what I meant for php
/agree
I agree. For HTML, CSS and XSLT etc. where it’s possible to use hyphens, I always use them. Otherwise, camelCase will be used.
Also you typed ‘hyphen’ as ‘hypen’ in the poll…
I’ve been told the mirrorside of what Rob says. Namely, that php doesn’t allow hyphens. So since I dislike underscores, I was left with using camelCase.
And in CSS/HTML I like to use hyphens due to the selectability (try it: test-test, test_test) and I don’t use camelCase in CSS/HTML due to hyphens being easier to read in a css-file (using “mostly single-line” style) I can easilty see a tree-like structure this way.
Tho in PHP functionnames I’m 100% underscores . .
I used to do camelCase everytime, everywhere, then i migrated from Mysql to Postgresql and, becose postgresql doesnt allow camelcase in tables/columns name (but just lower-case), i got stuck.
I like to use the same ‘formatting’ on every language, so that’s it: hypens where they are allowed, underscores just everywhere else (php, for example)!
Interesting – I can select the whole phrase with underscores, but not with hyphens. At least in the browser, in Safari, and I checked – also in text editors… that counts as a point towards underscores in my mind.
As for readability – I feel underscores are more readable as separate words.
Sadly, however, I am not terribly consistent with this and have my own “logic” (which might be fairly random at times). I need to change this bad habit… but I prefer allonewordlowercase for some situations, then underscores_between_words, then hyphenated-words-if-they-are-more connected, and sometimes a combination_of_underscores-and-hyphens, which is just silly, and occasionally, camelCase, but that is mostly for javascript and php. If I had to pick one for html/css, I would go for underscores for readability and selectability.
Underscores in css classes and id’s
CamelCase in php functions.
i second
I’m exactly the same, just seems right to me.
Always camelCase :)
i like camelCase.
html/css: #search_bar [underscore]
functions: def myFunction [camelCase]
classes : class MyAwesomeClass [CamelCase]
I dont use hyphens anywhere.
with dilse
I like hyphens. I tend navigate with the keyboard and use command arrow a lot for jumping from word to word.
Hyphens are the only of those options which allow jumping between the inner-words. If I misspell an inner-word, it allows for easy navigation for fixing the problem.
Hypens are for true coders because there’s no shift key involved. And everyone knows that true coders are the laziest people alive. Hyphens cut work by 50%!
camelCaseIsNice()
What’s “casels”?
Hyphens in CSS/HTML and Camel Case in everything else sounds good to me as well.
Used to be an underscore guy, but now there’s is no way I’d use anything other than hyphens. Cleanest option by far.
I don’t do much programming, however, and I understand camelCase is used often there.
Why does it matter?
It doesn’t. Whatever works best for an individual is, by default, the best method.
Doesn’t mean that people can’t put their heads together to see how other people do things, however.
html/css: #search_bar [underscore]
functions: def myFunction [camelCase]
classes : class MyAwesomeClass [CamelCase]
I dont use hyphens anywhere.
Python Coding Style says CamelCase for classes and camelCase for functions
imho, python coding style (pep8) actually says ‘_’ for functions.
That’s are great..!
camelCase FTW!
Saving your bandwidth, 1 byte at a time!
LOL. Yeah, Minimalism rulesz xD
css: dashes.
programming c#: camel case (and pascal case)
when I write ruby (not very often): underscore (but i don’t like it too much because I have to press an extra shift).
I use the different styles because of the “best practices” of each language.
camelCase FTW! No matter what I’m writing in.
Also, thanks for posting this, I’ve often wondered what other people use.
Did I miss where you say what you prefer?
camelCase is perfectly all-round. I use it in CSS classes and ID’s as well as in PHP and Javascript variables and functions.
Hi. In css use only hyphens, in php only use underscores, in use only java and javascript only camelStyle… :))))) – honestly!!! :)))
I’m a camelCase guy ;)
Hyphens in CSS and HTML attributes. Read somewhere that older browsers glitch if you use underscores.
In other programming, I use underscores for variables and function/method names. Looks cleaner, in some way. Camelcase is not very readable I think.
I used to strictly be an underscore guy, but I’m starting to switch to hyphens because I type them faster.
I tend to use camelCase more than anything. But sometimes I do use hyphens. I absolutely HATE underscores. They are really hard for me to type. lol. So I avoid those as much as possible.
I always prefer…
HTML & CSS: hyphens
PHP & JS: underscores
VB.Net & C#: CamelCase
This is how I program too.
Aye, the way I program as well.
I may be weird but all three.
CSS is the dash.
PHP varibles underscores
PHP functions and JS Camelcase
Same for me.
How about a keyboard with a special underscore button so you don’t have to use the shiftkey
Programming: CamelCase
CSS: dashes
I really hate underscores. They take way too long to type. I use dashes in CSS because I like to keep as much stuff as possible in lowercase in my HTML.
CamelCase! MuchEasierToTypeAndTheReadabilityIsn’tHardAtAll. IfAnythingItMightJustImproveYourReadability.
I didn’t vote in the poll since it depends.
Anything a search engine can read you’re better off using dashes. Otherwise just be consistent.
I typically use underscores when programming, but even then it depends on the language. I try to use whatever seems most common in the particular language.
Between hyphens and underscores, such as in URLs, I always use hyphens.
Programmatically, I’ve preferred hyphens as well, but several languages don’t support them in variable and function names, so lately I’ve been migrating to CamelCase.
I generally use hyphens, though I slip-up and use underscores once in awhile, as I tend to name PHP functions along the lines of the_function_name(). I’m really not a fan of camelCase. It seems less legible to me.
It depends on what I am doing. With CSS & HTML I use hyphens, with AS3 I use camel case and underscores (for variables and constants respectively). Since this is a CSS blog I imagine you only meant for CSS use so I voted hyphens :)
Which is more search engine friendly? I was always told that using hyphens is the optimal way of write multi-word file names or URLs. Edumacate me!!
Hyphens are best when it comes to URLs – but what you use in programming doesn’t affect SEO.
Hyphens are in fact search engine friendlier as google is able to split by them but not by underscores. Underscores count as characters and though glue two words to a single big word which is unlikely to be a SEO keyword. CamelCase words can never be split by search engines as there can be no formal rule how to split.
It is however very unlikely that CSS classes and IDs will be considered by search engines.
I have always been fond of using underscores.
When working with rather large amounts of code underscores make the ascenders more visible and therefore easier to read (we read words largely by the shape of the word, and not letter by letter).
Hyphens and, to a much larger degree camelCase, has the effect of making the words look more like one big word, making it more difficult to quickly locate what you are looking for:
1: $this_is_a_variable
2: $this-is-a-variable
3: $thisIsAVariable
The first line has much more air between the words.
Well, that is just me.
I agree with you, i use underscores all the time, i have used camelCase, but then i find it hard to manage the code when i debug.
I agree also,
Underscores keep the words cleaner and more seperated then camelCase. For readability its win_win!
I use it for everthing is code: html/css, php and javascript.
Chris, I think you should specify when, since some of us, including myself, would answer like so:
Programming: CamelCase
CSS: hyphens
I think I will go with hyphens for the poll though ;)
I use_underscores in my CSS and PHP.
I just don’t like the look of hyphens, and I heard that it was best to keep everything lowercase.
This isn’t really fair. I try to match the accepted idioms of the languages I program in.
For CSS I use either underscores or hyphens depending on my mood. :)
For PHP and JavaScript I normally use underscores for variables, camelCase for function names, and MixedCase for constructors or object literals.
For Ruby I use underscores for both variables and functions.
For friendly urls I always use hyphens, all lower case.
Perhaps you need to limit the scope of the Poll to one language… maybe CSS ?
Unless I’m trying to save bandwidth, I use hyphens. Or limit myself to one word. Otherwise, I use CamelCase.
CamelCase
I like using dashes for CSS class names, underscores for DOM IDs.
That’s a nice system, I guess it’s handy when you want to use an ID that’s similar or the same as an existing class name.
I do underscores…always have. No reason, I just always do it like that :D
#top-nav
function db_connect()
I generally use CamelCase for speed (and out of habit) but I’m thinking that I may try and use hyphens in CSS, mainly for when other people who don’t have a programming background are going to be working on the same files.
Would love to cast my vote, although I cannot do so on my iPhone . Have to when I get home I guess!
I use dashes, the reason: SEO friendly filenames.
I’ve read that search engines interpret underlines as ‘nothing’ thus “about_company_name.php” would be the read as “aboutcompanyname”, and that is only one word that wouldn’t mean anything to search engines.
On the other hand “about-company-name.php” would be understood as “About Company Name”, thus giving the page a relevant name related to the type of content that page would have.
With that being said, everything I do, when it comes to naming, I use dashes instead of underscores or camelCase styles.
That’s the reason I use dashes as well. I use dashes for image names too, like bg-li-a-header.gif…
yes cameCase for Programming
Hyphens for CSS Selectors
and underlines sometimes for files (esp. for PC Windows-Systems which I sometimes don’t trust?)
My favorites are dashes and camelCase but the best would be just a plain ________Space.
Variations on CamelCase, everywhere except constants, those are in CAPITAL_UNDERSCORE.
I have strict coding standards for PHP and JS and apply them to html/css as well.
Besides, using hyphens makes the code unreadable to me (allthough I understand some disagree with that) and underscores are a bore to use on the keyboard.
I use underscores for id’s and camelCase for almost everything else
Personally I use them all.
In my code I never (I mean ever) use hyphens. The only place I use them is in files that do not contain code. ie: images.
For files that contain code I use underscores for the name.
In the code itself, I use camelCase for class names and underscores for the functions and methods. Also, I preceed all the names of private variables and methods with an underscore, even with php5 syntax.
So for instance that would look like a private method in a class in my code:
class MyClass
{
private _some_var;
private function _my_function()
{
// some code
}
}
camelCaseIsNotBadAtAll
Since I come from a Flash / ActionScript background, it was natural for me to go straight to camelCase. However, a couple of casing hiccups in some web languages lead to me using underscores out of prudence.
Does anybody know if it really makes a difference to use uppercase?
for DB Tables underscore, but programing wise I am onboard with the consensus here.
I’m a CamelCase guy, but am inconsistent and sometimes just combine the words with no Camel, but never use underscore or dash.
For CSS and HTML I used underscores, but some time ago, I switched to dashes.
PHP – camelCase
That was a difficult poll to answer because it really depends on what we’re referring to here. I’m pretty much with everyone else on the comments here in that:
html / css / domain names : hyphens
js / php / perl / ruby / etc: camelCase
usernames and stuff like that I tend to go underscores if there is going to be a space…which I always try not to have.
HTML/CSS: Hyphens.
URLS: Hyphens.
PHP/JS: camelCase.
It’s always best to use hyphens whenever possible for readability, seo, and it just looks sexy to tell you the truth.
PHP/JS is best using camelCase considering underscores are just plain annoying. I like using underscores with variables though, otherwise functions and such are definite camelCase.
HTML/CSS: Hyphens
Everything else: camelCase
looks like you need another option on your poll ;)
camelCase to replace spaces between words, underscores to indicate important distinctions. eg: sampleFile_v01
I also dislike typing underscores. So I prefer hypens and camelCase.
Used to be an underscore type of person, but recently (like tonight after reading the comments), for CSS and HTML ONLY, I use hyphens for select ability, for everything else (PHP, Obj-C, JS, etc.) It’s camelCase all the way!
Most time: underscore, because they are easy to read
camelCase for almost anything.
Underscores out of habit, but it’s a habit I’m trying to break. Hyphens accomplish the same thing, but without getting the shift key involved, so why don’t I use them? No clue.
ILoveCamelCase…
Since I do a lot of programming in Rails, I have to use all three of those — camel case for classes, underscores for function names and hyphens in CSS. But if I prefer hyphens, because I can avoid the shift key there.
Hyphens are nice. Hate underscore. Sometimes CamelCase.
I like camelCase, and always use it for almost programming language.
Anyway just curious, what about your filename like
– filename.php
– fileName.php
– file_name.php
Coming from an XML/XHTML side of things, I’ve never used camelcase because of the all lowercase standards.
And since PHP has had trouble with hyphens (or so i’ve heard) I’ve always defaulted to underscores for everything.
The web motion and CSS 3 advents makes me feel that a near day we’ll have CSS expressions using hyphens. I know JavaScript libs were hyphen is already a selector, and who don’t know “-moz-opacity”…
Underscore it’s not easy to type, but it’s a convention in many programming languages, were camel would not be very semantic.
I use all camelCase, saving 1 byte, compact code and anything that saves connection time. If i build a common css widget… i name as package clock_nav (for a clock widget).
I’ve done lots of research on JavaScript and CSS to build my lib (leaf.googlecode.com). The main point is what will come next about CSS expressions.
Sorry about my English and laarge comment. I felt that I should say it.
iLoveCamelCase… :)
Depends on what I’m doing.
– PHP / Java / CSS – Camelcase
– URL’s of websites – Underscores
– C# – PascalCase
– Almost never use Hyphens (unless I have to, like with CSS properties “margin-left”)
actually i do prefer milk with my coffee.
Interesting discussion going on… I love using camelcase always…
-Deepu
follow CSS build-in style use Hypens.
I don’t care too much as long as it’s consistent throughout the code. For example, Drupal and WordPress use underscores in all function names; Symfony and CakePHP mostly camelcase.
I agree with other people in terms of it depending on the language; html/css dashes are fine – in php they are not allowed.
In xhtml/css I use hyphens, in php or python I use CamelCase it is more readable to me
Agreed.
Seems to be one option missing. Lowercase only.
Yea and another two is missing.
tHiSiSaVaRiAbLe and THISISAVARIABLE
Those 2 and lowercase only are just not an option, because they are hArD tO rEad (aren’t they?)
Why the heck would you use lowercase only?
are* missing.
I used underscores since i started coding, but tried camelcase few months ago and it seems it’s the best.
camelCase, and underscores rarely
camelCaseFtw =3
btw, I Forgot to mention that… to make my camelCase really work for me, is better to use smaller words. =)
Mostly CameCase (I don’t want speacial chars in my variable or function names names)
I started out using camelCase when I was in college working on my IS degree. Now I’m mostly a hyphen guy.
Hyphens for CSS, HTML and file names, camelCase for eveyrthing else.
It all comes down to my fat fingers… hyphen is much easier for my thick digits than underscore.. of course there is the cases where the underscore is necessary but I try to avoid twisting my fingers around as much as I can
I’m personally all about hyphens but I’m mainly in HTML / CSS. I find-that-it’s-much-cleaner-and-easier-to-type, see?
When I’m working with Flash and making several movie clips I like to throw in underscores.
Example: my-movie_mc or myMovie_mc depending on what mood I’m in I guess :P
I’m cracking up that all you self-described “lazy programmers” say using the shift key is such a pain – yet you have to use it for camel case! I guess I’m a fast (nimble-fingered?) typer so I don’t have any issue using underscore, and I like the readability of it. As a grammarian, I like underscores for semantics, too – they convey separate_words better than hyphens, which are for connected or related words (grammatically speaking, anyway).
For very short two word phrases, though, all lowercase using no shift key, no special characters, and is fastest and leanest. but for longer words and/or phrases, readability suffers.
camelCase = shift + letter key
underscroe = shift + underscore key + then letter key.
-1 move = 1 step forwards
And i agreed with you about the longer words and phrases, but i think there is always a way to make your id, or your class, or your var, or function name shorter. So i don’t worry about huge phrases wrote in camelCase. xD
Hypens, because on mac (PC users, sorry!) if i double/triple click on a list-of-words i can directly select just what i want.
Always camelCase. CSS, Coldfusion, PHP, Java, you name it, I camelCase it. I guess there is one exception, I never use it with HTML, but I’ve never seen a need to use any of the above with HTML.
On a side note. A lot of people above say that you shouldn’t use camelCase in CSS. Why?
Hey, Chris,
I always had the delusion that Google might be able to read hypen’s better and doing the hypen thang for HTML/CSS might help propel my sites up the Google food chain. Any truth to this… or another myth bites the dust?!
I’ve heard the same thing: that a hyphen is read by Google as a space, whereas an underscore is not. Not 100% if its true, but it makes sense to me.
I use CamelCase for class names, camelCase for function and variable names, and underscores for CSS and database stuff.
HTML / CSS – Hypens,
Functions – camelCase,
Classes – CamelCase
I hate using underscores.
HTML/CSS – hyphens (no camel casing because this technically invalidates CSS, even though I don’t give two sh*ts about CSS validation :))
Javascript/PHP – camelcasing (except I’m sloppy and sometimes use underscores for JS variables)
I like using Camel Casing most of the times.. but in C I have seen this trend of using underscores..
With CSS, classes that are related I’ll give similar prefixes to using hyphens (ie: #hd-about, hd-#cont, etc). For everything else (including PHP), I tend to use underscores.
I don’t think I’ve ever used camelCase.
I rarely comment on posts on any website, however, i just want to tell you how awesome this site is. This simple polls have been really interesting to see.
sadly i use all of the above >_>
camelcase the most since my programming teacher in college required everything that wasn’t a class name be camelcased.
I’m going to throw in the always helpful: “It depends”.
OOP Code: camelCase
HTML/CSS preference: hyphens.
Lately, I’ve had to plug in the ugly underscore, because that’s how ASP.NET decides to mangle IDs together when you dynamically create them.
HTML & CSS ~ Hyphens
PHP ~ CamelCase
I like to go camelCase.
Using php, Javascript and HTML/CSS, I use camelCase for everything in the name of consistency which I feel helps avoid some of those silly little mistakes which inevitably take hours to spot!
I agree with some of the above comments that it’s considered bad form for HTML and CSS, but personally I find camelCase works well universally and makes it easy to find or match up ID’s within HTML/CSS/Javascript/php.
I develop web and desktop applications so for the web, most of the time PHP, i use underscores, but in desktop i use camel case .
loll so which one should i choose
I mostly use camelcase as I also hate using the extra shift at times.
I personally use underscores for most things since it is really easy to read and easy to select (double click) the variable. The hyphens don’t allow you to select words as easily with the double click, but they are more standard for Google to read them as separate words. Therefore I use the hyphen only in the URLs. CamelCase is to hard to read for me.
As others have said – camelCase is my first choice for id or class names, but when it come to image-names, hyphens are the way to go as Google and other search engines have started referencing images for SEO and hyphens are seen as blank spaces where as under_scores and camelCase will be read as one word.
So if you use camelCase what about function name which return boolean value. Do you use for these function: is_integer() or maybe isInteger()?
It really depends, I have a system that I use that helps me speedily see where a variable/function/class resides/belongs
CSS Classes and IDs are-dashed (Read somehwhere it works better)
Local/Private/Protected variables and functions are_underscored
Public Variables/Functions and all Non-CSS classes are camelCased.
Works for me.
Hyphens are better for SEO from what i’ve read.
Always used camelCase must be from being taught VB6 at college.
frmContact
btnSend
labelCaption
Recently i started using hyphens for html, it just reads better in the mark-up.
I was an underscore guy until just a couple of months ago. No real aesthetic reason, just a matter of efficiency. Using a hyphen is one less keystroke than underscore or Camel Case (no Shift necessary). Also, the only uppercase letters I care to have in my code are commented section titles.
I like to user a combination of underscores and dashes…
dashes for more related information and underscores to break it up
e.g. client_website-header
functions or variables or ids or important names > underscore
urls > hyphens.
i just don’t stand camelcase… it’s not readable friendly to me…
ThisIsWhyiDisLikecamelCAseIneedTodycryptIt!!
Hyphens-are-good-but-i-feel-i-need-to-concentrate-while-reading-it
But_underscores_totally_easy_to_read_for_me
moreover by using underscore i give the names more uniqueness and distinct look than other texts!
which helps me to memorize functions better and locating them much easier!
I use all three. CamelCase I use for user names on and around the web. Underscores I use for web URL’s and filenames. In my CSS markup I use the dash.
Can’t say I have a particular preference. Though you’ll never catch me with underscores and dashes in user names. Always opt for a space. Failing that the CamelCase wins.
camelCase works fastest and is my preferred style. Underscores are more readable. hyphened variables cannot be selected entirely with a double-click.
What? Hyphenated variables? Which language? C-style languages will think you’re trying to subtract, no?
I used to be an allCamelCaseGuy for HTML IDs/classes (They’re HTML IDs/classes, not CSS IDs/classes). But not easy to stick a Microformat in your page then is it? So I converted, eventually.
Underscores? Never. It was either early Opera or IE4 that wouldn’t select classes or IDs with underscores in them.
For those of us that ever had the pleasure Netscape Navigator would not read class or id values that included an ‘_’.
I much prefer verbose camalCase for functional programming and ‘-‘s for css.
I use hyphens all the time by force of habit stemming from the fact that Google doesn’t recognise underscores as spaces but hyphens it does. It looks neat.
I lean towards hyphens for anything I write and underscores for “native” code from the platform. Camel case, not since the mid-naughts. And I insist on calling them hyphens, not dashes, to the chagrin of my co-workers.
I use:
#underscores_for_ids
.hyphens-for-classes
and a mixture of camelCase_underscores-and-hyphens in programming, depends how I’m feeling at the time but I only use one per website.
I’ve moved to underscores for images and classes as out back-end technology is primarily .net and our developers have found issues with hyphens.
I’ve also dropped the use of ID’s due to the nagging I get from developers about .net client id’s and the refactoring for scripts and styles we end up doing. Have tried some work arounds but inevitably something interfere’s with the .net framework scripts.
Dashes for the IDs and classes in HTML/CSS and underscores for URLs.
I always use camelCase when in programming. From my point of view it’s more reliable and easier to read than hyphens or underscores. I use hyphens for URLs
client-side: Hyphens.
server-side: camelCase.