HTML Naming convention

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

Do more with

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

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

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".

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

A sample is available here:

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