Is there a best practice HTML Naming convention that I can use to name the table, buttons, div, etc2?
Web Languages and StandardsHTMLWeb Development
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".
tblXXX, divXXX, btnXXX, cmdXXX, chkXXX, optXXX
try use a standard name in front of your element, so that it can be recognize easily.