Closing tag with ID property

Omar picture Omar · Jan 16, 2012 · Viewed 8.1k times · Source

Question: If I close any html tag in this fashion (Including the id property):

<div id="tagid" >...more html
...
</div id="tagid" >

Will it affect the page, or won't like it, or disrupt any W3C rules...how can I put it...will it affect in any way?

Why?: Simply personal preference.
Instead of writing additional comments next to the tag, I simply add the id to help me know WHAT tag is closed -The tag is closed any way, so I guess it won't do anything (or so I think)

PS. FYI, I am a beginner

Answer

Jason Gennaro picture Jason Gennaro · Jan 16, 2012

No this is not valid.

While it might not break your code, it could!

You should just use the comments

</div> <!-- closing main content div -->


After checking, this

<div></div id="tagid" >

breaks in the validator

http://validator.w3.org/#validate_by_input


Although not specifically mentioned as illegal, the HTML spec only mentions attributes as appearing within the start tag:

Elements may have associated properties, called attributes, which may have values (by default, or set by authors or scripts). Attribute/value pairs appear before the final ">" of an element's start tag. Any number of (legal) attribute value pairs, separated by spaces, may appear in an element's start tag.

http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.2