HTML Naming convention

kecoak
kecoak used Ask the Experts™
on
Is there a best practice HTML Naming convention that I can use to name the table, buttons, div, etc2?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Ryan ChongSoftware Team Lead

Commented:
something like:

tblXXX, divXXX, btnXXX, cmdXXX, chkXXX, optXXX

try use a standard name in front of your element, so that it can be recognize easily.
Top Expert 2007

Commented:
There is no naming convention as such, although what ryancys suggests is often seen.  

DIV and TABLE elements don't even have a name attribute (but you can use the ID) attribute.

The HTML Spec has this rule:
ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").

I personally don't usually prefix names as they deliver little benefit.  Radio buttons could easily be refactored into a drop-down list, I'd prefer not to have the obsticle of having to rename the request parameter names on the server in the process.

When naming elements, try to capture function rather than appearance.  E.g., one should have "error" and "success" instead of "redCross" and "greenTick".

--
Lee
Software Team Lead
Commented:
It's depends on developer's judgement on what naming convention is best to suit themselves.

A sample is available here:
http://www.shiningstar.net/articles/articles/standards/HTMLnamingconventions.asp?ID=AW

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial