Setting attribute for closing HTML tags?

Can one set attribute for closing HTML tags? This id declaration would be only for the programmer’s usage, to keep himself organized, like this:

<div id="beer">
  <!-- Lots of code and newlines here -->
</div id="beer">

It is to replace this code:

<div id="beer">
  <!-- Lots of code and newlines here -->
</div> <!-- END id="beer" -->

no problem :slight_smile:

Thanks, noonnope. As the point of CSS is semantic names, it is not design consideration that the names will change over time. But that is a good point.

Also, naturally, I do not expect the browsers / UA to actually do anything with the added attribute, rather, it is only for the humans to read.


I wouldn’t say it is a bad idea, just not a syntaxically valid one.

while the reason is … what it is, the answer is yes, you can do it if you like.

UAs will probably try and make the best of it and render correctly.

your code will not pass validation though and your id attribute in the end tag will mean nothing in terms of css selector or javascript dom: no styling hooks possible based on it and no dom manipulation also. but its twin in the start tag will certainly get the job done if need it.

you need to go further with your thinking, this is just a bad idea :slight_smile: while the other attributes will make sense to another person changing your code, it will certainly be harder to keep it consistent after a while, considering that every time you change the value for the attribute you need to remember to do so also about its twin.

you’ll end up with invalid markup and its purpose defeated:

<div id="cold_beer">
  <!-- Lots of code and newlines here -->
</div id="worm_beer">

No, you shouldn’t do that. I can’t see what you’re hoping to gain from it.

The usual method of putting a <!-- end beer –> comment works perfectly well, and I see no need or benefit to changing it. Putting the id inside the closing tag would seem to imply that the browser should know which tag it is closing, which leads to obvious questions as to what it should do if you’ve opened <div id=“beer”> but you then close </div id=“cider”>.

Since an id attribute is required to be unique in the web page you are almost certainly going to break some functionality in a browser somewhere by using that invalid code. It could be the HTML, CSS, or JavaScript that gets broken and it may be a rare browser that hardly anyone uses but why break something by using invalid code when a perfectly valid comment is at least as clear (and comments are always obvious that their content may be out of date whereas code is usually presumed to keep itself up to date).