Avatar of kecoak
kecoak
 asked on

HTML Naming convention

Is there a best practice HTML Naming convention that I can use to name the table, buttons, div, etc2?
Web Languages and StandardsHTMLWeb Development

Avatar of undefined
Last Comment
Ryan Chong

8/22/2022 - Mon
Ryan Chong

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

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
ASKER CERTIFIED SOLUTION
Ryan Chong

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes