Why does content outside the body still display?


#1

i have the folowing code and it shows both < p>'s even though ‘Duie Mragnea’ is outside the body and yet in your course you say “Only content inside the opening and closing body tags can be displayed to the screen”

< body>
< p> Muie Dragnea!< /p>
< /body>

< p>Duie Mragnea< /p>


FAQ: Learn HTML Elements - Intro to HTML - The Body
FAQ: Learn HTML Elements - Intro to HTML - The Body
#2

I’m also having concerns on this one. It displayed the content though it’s outside the body.


#3

@sant513 @ciellyberry @radu_moon no need to be concerned. The correct format for a document is:

<! DOCTYPE html>

    <html>
        <head>
               For title and links to scripts etc. 
        </head>

        <body>
                For content of the site e.g divs
        </body>
    </html>

If your code is laid out in any other way a browser isn’t guaranteed to display it correctly.

Browsers create DOMs (document object models) from your code, and if your code has tags outside of body or head this can mess up the model and create some weirdly rendered results.

However browsers assume users might do things a bit wrong, so if you have tags outside the body tag they might assume you should have put it in the body tags and process it as if you had done so. But the important thing is every browser does this differently, so if you’re format isn’t correct it could look different on every single browser. To guarantee your HTML is processed the same on every browser you should put tags you want displayed inside the body tag.


#4

Same here I would also like to know this and it was said anything outside the body tag is not displayed but it seems to be working just fine. Text still displays outside of the body tag when type is there a reason for this?


FAQ: Learn HTML Elements - Intro to HTML - The Body