Why does content placed after `</html>` show up in the browser?

252 Views Asked by At

I attempted to store some text that I might use later after the </html> tag of my document (like I routinely do with \end{document} in LaTeX) but the browser still shows the text.

It was my understanding that the page is defined by what is between <html> and </html>, so why do things beyond </html> get displayed?

3

There are 3 best solutions below

0
On BEST ANSWER

This is because browsers try very hard to do the right thing with malformed markup. The solution is to only create well-formed documents.

If you really want to store cruft in your document, place it in an xml/sgml comment: <!-- this is a comment -->

0
On

Basically because the browser will render everything. To hide text to use later use a:

<div style="display:none"">Text</div>
0
On

HTML is a markup language. More specifically, it is a set of standards that web pages should follow in order to display content and make it more logical to the end-user, bots, etc. All content is supposed to be contained within the <html> tag in order to follow standards. However, a browser is more worried about displaying content, so they will display your elements no matter if they are within the element or not, just because they are there.

The main thing you need to worry about is actually following standards and making sure your elements are where they are allowed. Putting things in random places just to see if they still work will likely result in them, well, working. But just because things work doesn't mean it is semantically correct and follows standards.