0

html head tag

we can write messages in head tag same as we can write in body than what is difference between the two ?

15th Jan 2019, 5:43 PM
Vineet Chheda
2 Answers
+ 5
Paste this code into a CodePlayground code: <head> This content does not belong in head. </head> <body> <script>alert(document.all[0].outerHTML)</script> </body> Observe that the browser--reacting to illegal use of content in the <head> tag--ended the head tag and started a <body> tag to contain your content, breaking your intended document. If you had additional things in <head>, they probably end up in inappropriate places in your document (that happens here: when the CSS and JS tabs are inserted, they go in wrong). As for "why this works" -- because browsers are designed not to crash on you -- they try really hard to show you something like what you may have meant, even if they have to do something very wrong to get there.
15th Jan 2019, 7:04 PM
Kirk Schafer
Kirk Schafer - avatar
0
Anything that appears in the page is written in the body tag. The head tag provides the browser with some technical details about the page, such as the title that will appear in the tab, connections to css/js files, etc.
15th Jan 2019, 6:14 PM
giannismach
giannismach - avatar