Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do we really need to use </body> and </html> closing tags?

Tags:

html

More often than not I see HTML without the closing tags, especially body and html.

According to:

http://www.w3.org/TR/html5/sections.html#the-body-element

http://www.w3.org/TR/html5/semantics.html#the-html-element

This can be omitted, but what about cross device issues? Like running such HTML on androids or windows phone's or whatever you know where not having these closing tags this would not work.

like image 611
funguy Avatar asked Oct 26 '25 11:10

funguy


1 Answers

Do we need it? Well that depends on your DTD. If you're using XHTML, then yes, you will need it to conform. For accessibility sake I would include the closing tags, you never know if there's a screen reader (or other piece of software) out there that only parses valid XHTML, you could be hindering partially sighted people for example.

Google will also, apparently, rank your valid documents higher than invalid documents in their listings.

Here's a document by a friend of a friend that answers your question a bit better; granted that it was written in 2008, I think some of the points still apply.

If you ever need to use the same html in an XHTML application you won't need to mess around with it, you can just copy it across and not have to worry about conforming (because you already are).

On a separate note, you are essentially future proofing your markup. Who's to say that the spec won't eventually change to "You must include the closing head and body tags"? You won't need to worry if you already have them. It is, however, highly unlikely that the spec will change to, "You must not include the closing head and body tags".


As a great man once said:

Should I close the lid of the toilet when I'm finished? Yes, especially if the wife is going to use it after me. - Darren Gourley (Nov 2015)

like image 90
Darren Gourley Avatar answered Oct 29 '25 00:10

Darren Gourley