3

Possible Duplicate:
Why are dashes preferred for CSS selectors / HTML attributes?

Personally I use "lower-case with dashes" to format my HTML classes, which seems to be the standard these days. Using something like camel case seems more reserved for JavaScript in my eyes, but I realise that's just my opinion.

I'm trying to improve front-end code consistency at my workplace and part of that will be coding guidelines. Rather than just saying "we should do it this way" I'm keen to hear some valid reasons behind this common trend.

So the question in summary, what are some valid technical reasons for the "lower-case with dashes" trend for HTML classes?

Community
  • 1
  • 1
Alec Rust
  • 10,532
  • 12
  • 48
  • 63
  • 3
    "what are some valid technical reasons" There are absolutely none. This is also a duplicate of [Why are dashes preferred for CSS selectors / HTML attributes?](http://stackoverflow.com/questions/7560813/why-are-dashes-preferred-for-css-selectors-html-attributes) and [Hyphens or underscores in CSS and HTML identifiers?](http://stackoverflow.com/questions/1686337/hyphens-or-underscores-in-css-and-html-identifiers) – BoltClock Mar 16 '12 at 10:34
  • … other than the syntax allowing it. – Quentin Mar 16 '12 at 10:35
  • 1
    These are HTML classes though, there is no such thing as a CSS class. – Quentin Mar 16 '12 at 10:35
  • 1
    @Quentin: Which reminds me - every time I see that [css-classes] tag I have this scorching urge to obliterate it. – BoltClock Mar 16 '12 at 10:38
  • Good point about the CSS/HTML, thanks – Alec Rust Mar 16 '12 at 10:38
  • That probably comes from using too much Visual Studio. – Mr Lister Mar 16 '12 at 11:19

3 Answers3

3

There are none. It's an acceptable naming convention, to help the author from confusing between his different languages. You can name your class names in any way you'd like.

Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308
  • None at all? Code editor class completion? The fact that data attributes are lower-case? – Alec Rust Mar 16 '12 at 10:39
  • @alecrust: What does the fact that data attributes are lower case have to do with class names being lower case from a technical point of view? – BoltClock Mar 16 '12 at 10:41
  • if you mean `data-*` attributes, those are just as case insensitive as all other attribute names. – Mr Lister Mar 16 '12 at 11:23
2

Just like you mentioned in your own question but I realise that's just my opinion.

Coding-conventions are:

  • guidelines for making code more readable (amount of spaces for identation, naming of variables, ..)
  • in no way a limit in your coding
  • different for every language

In short, it's only a proposed way of coding which you don't need to follow but it's more readable for other people if you do.

If you come across one set of conventions, it means a lot of people agree with that set and adopt it for themselves (with or without some modifications =) )

Some languages restrict conventions a bit (like class names having to start with an uppercase letter, ..), that's why it's different for every language.

KristofMols
  • 3,487
  • 2
  • 38
  • 48
0

Coding Conventions are just that: conventions.

What is a convention? It's some rule how to do things?

Why is it like that? Because someone said so.

yunzen
  • 32,854
  • 11
  • 73
  • 106