Practical considerations for HTML / CSS naming conventions (syntax)

Posted by Jeroen on Programmers See other posts from Programmers or by Jeroen
Published on 2012-03-28T19:45:11Z Indexed on 2012/03/28 23:43 UTC
Read the original article Hit count: 395

Question: what are the practical considerations for the syntax in class and id values?

Note that I'm not asking about the semantics, i.e. the actual words that are being used, as for example described in this blogpost. There are a lot of resources on that side of naming conventions already, in fact obscuring my search for practical information on the various syntactical bits: casing, use of interpunction (specifically the - dash), specific characters to use or avoid, etc.

To sum up the reasons I'm asking this question:

  • The naming restrictions on id and class don't naturally lead to any conventions
  • The abundance of resources on the semantic side of naming conventions obscure searches on the syntactic considerations
  • I couldn't find any authorative source on this
  • There wasn't any question on SE Programmers yet on this topic :)

Some of the conventions I've considered using:

  1. UpperCamelCase, mainly as a cross-over habit from server side coding
  2. lowerCamelCase, for consistency with JavaScript naming conventions
  3. css-style-classes, which is consistent with naming of css properties (but can be annoying when Ctrl+Shift+ArrowKey selection of text)
  4. with_under_scores, which I personally haven't seen used much
  5. alllowercase, simple to remember but can be hard to read for longer names
  6. UPPERCASEFTW, as a great way to annoy your fellow programmers (perhaps combined with option 4 for readability)

And probably I've left out some important options or combinations as well. So: what considerations are there for naming conventions, and to which convention do they lead?

© Programmers or respective owner

Related posts about coding-style

Related posts about html