user1729506
user1729506

Reputation: 975

What can be validly placed between </body> and </html>, if anything?

I get a lot of requests from clients, all of whom are working with ad agencies and SEO firms, who insist on having all kinds of tags and scripts placed after </body> and before </html>. I always thought this was inappropriate, but it is asked for quit often. Some people even become upset and demanding when the code I insert is not explicitly between those two closing tags.

Is this in any way an acceptable HTML practice? If so, why? And what benefit would it even provide?

Upvotes: 1

Views: 84

Answers (3)

CheckeredMichael
CheckeredMichael

Reputation: 571

Nothing but comments should be placed there and even comments won't have any effect on SEO or page ranking as search engines don't read comments. Script tags should be placed just before the </body> as that will make the page load faster, but should not go between </body> and </html> as that is really bad practice and will probably mess the website up as the browser might render it differently.

I think your clients must be reading instructions incorrectly and you should probably ask them where they got their information from. A lot of sites which ask you to place script tags will always say before </body></html> and they might be misreading the before text.

If you are ever unsure, then please check http://www.w3.org/ and validate your code through http://validator.w3.org/.

Upvotes: 0

Jukka K. Korpela
Jukka K. Korpela

Reputation: 201896

No published HTML specification allows any tags between </body> and </html>, because the body element may only appear as the last child of the html element. This is defined by the content model of the html element.

What exactly is allowed there depends somewhat on HTML version, but the most permissive version in this respect, HTML5 CR, allows (by the general rules on Content models) “Inter-element whitespace, comment nodes, and processing instruction nodes”.

If you put some elements between </body> and </html>, browsers actually treat them as appearing at the end of the body element. That is, they simply ignore the </body> tag. (If you put elements after the </html> tag, browsers similarly interpret them as being in the body. So the </html> tag has no impact, really.)

Putting anything between </body> and </html> is normally a pointless risk, since browsers could behave differently, and normally nothing should prevent you from putting your elements before the </body> tag.

Upvotes: 1

stephenmurdoch
stephenmurdoch

Reputation: 34653

You don't even need the html or body tags.... Except for certain situations but you can put comments between them if you like, but why would you?

Upvotes: 0

Related Questions