Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is using camelCase in CSS ids or classes ok or not?

Question is in the title. I'm used to using camelcase in development and, since there are crossovers with design, was wondering if there are any technical reasons (regardless of opinions) against using it in HTML. Thanks in advance for your replies.

like image 253
James P. Avatar asked Jul 10 '12 10:07

James P.


People also ask

Should html ids be kebab case?

For SEO (read as: the way Google does things), URL path names should be kebab-case.

How do you name a css ID?

The CSS id Selector To select an element with a specific id, write a hash (#) character, followed by the id of the element.

What is CamelCase example?

Meaning of camel case in English. the use of a capital letter to begin the second word in a compound name or phrase, when it is not separated from the first word by a space: Examples of camel case include "iPod" and "GaGa".

How do you name a class and ID in html?

Always favor lowercase, for elements, for attributes and their values, for classes and ids. Multi-word names for classes and ids should either 1., concatenate the words in lowercase without any in-between character, or 2., separate each word with a "-" (not "_") and maintain lowercasing throughout.


4 Answers

There is one technical limitation if you use camelCase identifiers in your CSS - the |= selector specifier:

<form class="registration"></form>
<form class="search-movies"></form>
<form class="search-actress"></form>

To match only search forms, you can write:

[class|="search"] { font-size: 150% }

You cannot do this with camelCase class names.

like image 150
srigi Avatar answered Oct 21 '22 15:10

srigi


Technically, no, there are no technical issues. Do what you like.

Do try to follow a good style-guide though, like this one.

like image 21
Jezen Thomas Avatar answered Oct 21 '22 17:10

Jezen Thomas


I'd been using camelCasing before today, let me tell the story: I created a bootstrap modal by the id name written in camelCasing. I couldn't manipulate it using bootstrap's own JQuery function. After searching for days, finally my co-worker found out that camelCasing was causing it. JavaScript case sensitivity can be tricky and unpredictable. So I suggest you to use hyphens.

like image 38
Kutalia Avatar answered Oct 21 '22 17:10

Kutalia


Good question. I personally use camelCase in class/id names.There is no technical reason why you can't.

However, after doing some quick reading on opinions, it seems alot of other developers/designers use hyphens over camelCase due to better readability.

Go with what you are comfortable coding in. I have got by fine using camelCase, I work in a team environment and never had an issue with readability for other developers.

Opinions on this that I have been reading can be found here: http://css-tricks.com/new-poll-hyphens-or-dashes/

like image 35
Dave Haigh Avatar answered Oct 21 '22 16:10

Dave Haigh