I have a general query regarding name of html elements.
I have seen in the past developers placing an prefixes before the id of their html elements eg for a div element -> dvMyDiv
I have seen a mix of casing when naming elements. Similar to that of assigning name to element classes.
So I am wondering is there any standard or convention to what html elements should be named? What casing? Should they have prefixes etc?
I am working with asp.net web forms, html5, css3 and jquery so would like some form of standard for naming conventions that I can share with other developers.
I agree with consistency – if you already have a convention, then stick to it.
However, if your making a new convention, this kind of Hungarian notation can be a really bad idea because it’s not at all DRY. For example, the name of the tag is
<div>and then the name of your class again says that it’s a div. If you change from using<div>s to<section>s, either your code will be out of date or you’ll have to change all the class names as well (possibly in HTML, CSS and JavaScript). Since you can target classes using code likediv.classname, it adds absolutely no value.A better idea is to name things after the type of content they include. For example, in a blog, you might use HTML like this: