tags:

views:

347

answers:

5

W3c validator didn't ding me on this, but I was curious if anyone else had an opinion on placing html comments outside of the html tags?

...
</body>
</html>
<!-- byee -->

I have an application and am outputting some data and want it to be the absolute last thing that is done, which unfortunately means I've already attached my last </html>.

+1  A: 

Any client should completely ignore comments, so they should not cause any problems. Anyway if the validator didn't complain it's probably ok.

krusty.ar
+7  A: 

I can't see this being a problem - allowable comments are not specified in a DTD (as they're effectively for humans, not computers). Also, the DOM API (http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html) explicitly allows many comments directly under the document node (i.e. not the root HTML element, the logical document root), so any conforming browser should allow it.

This is not to say you won't find browsers or tools, especially older ones, that choke. But I'd be surprised if there were many.

Adam Wright
I have not seen any browser complain about this. Just for fun I tested in the ancient Mosaic 2.1.1 (from 1996!!) and even this very old browser didn't complain.
some
+6  A: 

I don't think a comment after the </html> will cause any problems, but I believe that a comment that precedes the DOCTYPE declaration (and therefore before the <html> tag) will kick IE6 into quirks mode.

Alohci
A: 

Yes by all means. Any rendering engine (IE, Firefix, Opera, Safari, etc) will ignore any HTML comment tag completely regardless which position.

manetic
This is not technically true as IE parses comments for conditional statements. See: "http://msdn.microsoft.com/en-us/library/ms537512(VS.85).aspx
Zack Mulgrew
A: 

You should probably use

/* */

for comment flags as

<!-- -->

has another meaning

Supernovah
At least one of us is confused.
Will Wagner
@Supernovah: whar r u talking about?
Marco Demajo