Reputation: 8271
It is typical in web projects to have multiple solutions work together to produce the desired outcome. In my case, I am currently working on a project that uses the following: HTML, CSS, JavaScript, jQuery, AJAX, JSON, PHP, MySQL, and some other libraries. This is a typical set of technologies for the average project.
At one point throughout the project, and as you might expect, you would need to interact with data that goes across from HTML to PHP via an AJAX call as a JSON object after being processed by either JavaScript or jQuery, and of course this input data is styled via CSS when displayed to the user.
An example of such HTML element is the following:
<input type="text" name="my-input-name" id="my-input-name" />
Note that the name and id are hyphenated. This could also be written as
<input type="text" name="my_input_name" id="my_input_name" />
Or
<input type="text" name="myInputName" id="myInputName" />
That name and id is what could be used by all the aforementioned technologies.
Personally, I prefer hyphenated for CSS, underscore for PHP, camel case for AJAX, and so on.
But then this means the name and id will not follow the desired naming convention in at least one of the used technologies.
I read many many different opinions (including some in Stack Overflow), but none really provided any final conclusion.
So, my question is, which convention should I use? What is best in HTML 5 and CSS 3 era?
Thanks
Upvotes: 2
Views: 1242
Reputation: 744
It really depends on the style/standards of the project you are using. I've seen all three styles you mentioned. If I may make a recommendation though, I've seen dashes "-" break certain scripts in a Linux environment. Also, underscores "_" are sometimes considered extra clutter if not needed.
If no other style concerns are important, I would recommend the third option of camel case (myInputName). The reason would be in a web environment, things have to be re-compiled each time, so fewer characters are slightly less processing.
Upvotes: 3