Best Naming Convention?

Which of these 3 naming conventions is best for my HTML form and why?


<li>
	<label for="firstname">:</label>
	<input id=firstname"" name="firstname" class="text" type="text" />
</li>

<li>
	<label for="first_name">:</label>
	<input id="first_name" name="first_name" class="text" type="text" />
</li>

<li>
	<label for="FirstName">:</label>
	<input id="FirstName" name="FirstName" class="text" type="text" />
</li>

I believe HTML is case-insensitive, but maybe it makes a difference when I use PHP with this form?!

Thanks,

Debbie

The ‘id’ and ‘name’ is case sensitive; some values in HTML are actually case sensitive (i.e., user agents interpret “a” and “A” differently).

As are any interactions with the DOM.

Personally, I either use all lowercase (rarely) or camelCase (95+% of the time).

So my choices would be:


<!-- preferred -->
<li>
    <label for="firstName">:</label>
    <input id="firstName" name="firstName" class="text" type="text" />
</li>
<!-- acceptable -->
<li>
    <label for="firstname">:</label>
    <input id="firstname" name="firstname" class="text" type="text" />
</li>

Yeah, I decided on camelCase

Thanks,

Debbie

In the end it actually comes down to personal preference. I, for example, don’t like camel case that much (also because I don’t like Java so much :stuck_out_tongue: ) and I prefer to separate words woth an underscore instead (first_name).

The most important aspect is consistency. Pick one way and use it everywhere.

I agree.

Debbie

On new projects I use separate words with hyphens. When working on an existing project I try to follow any obvious patterns. I much prefer separate words, all lower case w/ hyphens. Server and client-side programming I tend to go with camel case except in templates where the convention seems to be underscore or form field name attribute.

Although, I think I would be slightly irritated if I had to deal with names like: firstname where all words were just squashed together. That to me just seems highly unreadable in comparison to the alternatives that at least have some type of visual break between words. Besides that though I don’t think there is a best way to name classes and ids. Pretty much what your are comfortable with until you inherit another persons work.

We must also say that the conventions tend to change with the programming language, so there really isn’t any “correct” way.