Grow your CSS skills. Land your dream job.

Poll Results: Hyphens, Underscores, or camelCase?

Published by Chris Coyier

My intention with this poll was to be kinda vague, so that people would respond about what they like the best instead of thinking of one particular instance of usage. Usage could be where ever you need to manually name something: CSS classes and ID's, programming function names, file names, usernames and passwords, basically anywhere you can't use, but benefit from simulating, spaces.

Turns out the vagueness was problematic. For example, you might love hyphens (I do), but you can't use hyphens when naming PHP functions. The poll results would have probably been more useful if it was limited one one particular language. Ah well. Inherent flaw aside, camelCase took the win at 45%, and hypens edged out underscores for 2nd place, 28% and 27% respectively.

New poll in a few days.


  1. Permalink to comment#

    Wow, im one of the camelCase+hypens when possible, but i would bet on the underscores, i find so many script with them!

  2. Liam Goodacre
    Permalink to comment#

    I use camelCase for CSS and programming all the time, I think it looks the nicest.

    I see a fair few people agree ^_^

  3. Permalink to comment#

    Ah crap, I’m in the minority…for some reason I can’t stop using underscores.

  4. Maor
    Permalink to comment#

    this_is_the_type_ftw! (oh, especially for PHP)

  5. I use hyphens for CSS, and underscores when I’m writing function names in PHP and Ruby on Rails projects. And in Rails, I have to use CamelCase for class names. So I actually use all three equally, but I feel under_scores look most readable.

  6. Surprising results, as you mentioned it would be interesting to see the brake down by programming language.

  7. Permalink to comment#

    I use _underscore for css/js/php/html . CamleCase for action script.

  8. Permalink to comment#

    camelCase for everything!, it saves a Byte everywhere :P

  9. Permalink to comment#

    Indeed the waters were quite muddied with this poll as many people have different preferences for different languages (I use hyphens in HTML classes/IDs, but underscores and camelCase in JS and PHP).

    I’m looking forward to the same “Hyphens, Underscores, or camelCase?” poll strictly for HTML class/ID names.

  10. People have their own standards which is nice to see.

    For me, hyphens for CSS, underscores for PHP but I use camelCase for functions in both PHP and JavaScript.

    Mostly because it looks nice. Oh and hyphens for file names as well, unless it’s being included/used via PHP, then it’s underscores.

  11. Shouldn’t it be “peopleLikeCamelCase” ;)

  12. Mini0n
    Permalink to comment#

    I like the hyphens the most, but since I can’t use them everywhere, I go for underscores for everything except JavaScript function names, where I use camelCase.

  13. I use camel case for PHP and JavaScript, underscores for MySQL database tables, hyphens for CSS… Cheers :)

  14. Eliezer
    Permalink to comment#


  15. Permalink to comment#

    Hyphens (where usable) win easy for me, because they’re fastest–no shift key.

  16. bjerh
    Permalink to comment#

    CamelCase… Not so long ago I was sorta split between using CamelCase and hypens I wasn’t in particular for the one or the other… But after having installed the newest beta branch of Chrome for some time ago, I chose to use CamelCase since all css-classes with hypens ceased to function.

  17. Shift key = bleh

    I use hyphens whenever possible, but when I can’t, camelCase if possible. Hyphens have better readability than camelCase, and less keystrokes than underscores.

    this-poll = 9 characters, 9 keystrokes
    thisPoll = 8 characters, 9 keystrokes
    this_poll = 9 characters, 10 keystrokes

  18. Permalink to comment#

    Hyphens whenever possible. I really hate having to be case sensitive. I use hyphens for all my URLs and stuff too :)

  19. CamelCase forever :) Looks cooler :)

  20. Permalink to comment#

    I use all three in different situations:

    For CSS class names, I always use a prefix and hyphens. So if I’m coding up a site that’s called “super awesome funtime” I would make classes like “saf-header”. I picked up the prefix thing from YUI’s CSS files, as I make a lot of YUI-based widgets, and I find it is a great practice for keeping things organized in mashup environments.

    I use camel case for function names when programming, for example regularMethod() and ConstructorFunction().

    In some special cases I will use underscores, but I tend to find them ugly and so I avoid them. In PHP, for instance, I will use underscores to group related constants. Being in all-uppercase by convention, PHP constants are already ugly as it is. :) In other situations where you might use underscores to group like variables, I tend to just use a hash of values instead.

  21. Permalink to comment#

    I tend to use hyphens for URLs, underscores for file names. Don’t use camel case for much but I’m sure I’ll find a use for it somewhere eventually.

  22. I usually use CamelCase for most situations, PHP/JS/ActionScript/C…

    Actually I’m using hyphen on CSS for my new blog template.

    Underscores I use mostly on filenames (photography) or in some special cases on PHP.

    Sometime ago, I used underscores in C for arguments variables, but I discard that habit…

    Let’s see if it goes well :)

  23. Josh
    Permalink to comment#

    I’m with Mario, being a Java programmer by profession – I use camel case for Java, PHP and JavaScript, underscores for MySQL database tables, hyphens for CSS.

    Poll was too vague as you said. :)

  24. I’ve got to say that I use hyphens for URL’s and CSS classes but definitely underscores for PHP (although, I’m really starting to like CamelCase for PHP).

    I find though that I am at a crossroads right now. I think we all try on different ways to code/program and I’m at that place where I’m examining different procedures to complete tasks.

  25. I use CamelCase. Well useful stats.

  26. Johen
    Permalink to comment#

    hypens for css. camelCase for PHP and JavaScript

  27. Permalink to comment#

    camelCase for programming (JS, PHP) and css class names unless its a constant name, then its all uppercase with underscores.

    underscores for SQL names (I like using upper case for SQL commands and lowercase for my table/column/view/stored proc. names)

    i use hyphens for css id’s and form element names as it makes it easier to split them in JS/PHP, so I can add complex heirarchical ownership into the id/names. I’ve even had to use hyphens and underscores when I had to dynamically match table/column names within form element names.

  28. I think underscores are probably most readable, but it depends on the genius of the language what I’ll actually use. In general I try to mimic the language I’m using. So:

    * Hyphens for Lisp.
    * Underscores for Ruby, PHP, Perl, etc.
    * camelCase for Java, JavaScript, C, Ruby class names.

    CSS…well…I usually use hyphens or underscores. But these days I’m dynamically generating most CSS with Sass, usually in a Ruby context, so I’m thinking more of Ruby aesthetics than CSS aesthetics anyway.

  29. jygz
    Permalink to comment#

    I use TitleCase… You should’ve included it in the pool..hehehe… I voted for camelCase.

  30. jygz
    Permalink to comment#

    ^ Sorry typo error: I mean “poll” not “pool”..hahaha

  31. camelCase for programming / css & hyphens for search-engine-optimization. I wish everyone was like that.

  32. James
    Permalink to comment#

    Hyphens and underscores are extraneous, since capitalizing the first character of each word in the name is sufficient to delimit them. Arbitrarily uncapitalizing the first word in the name as in camelcase is stupid and makes no sense. However, I preface the name with one or more prefixes and make them all lower case to differentiate them from the name – for example, fldintProductId is a field of type int and its name is ProductId, stylLeftColumn is a css style called Left Column. This convention is applicable regardless of dev environment or language. Thus, unlike everyone else, I use camelcase for a reason that does make sense and that is not stupid. I think.

  33. Permalink to comment#

    What I use:

    – camelCase for all object-oriented programming (C++, JavaScript, Java, Ruby, PHP classes)

    – uderscores for procedural programming (PHP functions)

    – hyphens for HTML and CSS (classes and ID’s, HTML filenames, URL’s)

    This seems to be fairly standardized, so why buck the trends?

This comment thread is closed. If you have important information to share, you can always contact me.

*May or may not contain any actual "CSS" or "Tricks".