Why does content outside the body still display?

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>

3 Likes

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

4 Likes

@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.

145 Likes

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?

2 Likes

If you want the technical answer, I don’t know. If you want the one that answers why simply compiles fine, the answers is above your comment.

2 Likes

I’ve tested this code. It still displays text outside the body tag,
Can it be my browser? I’m using the latest version of Google Chrome.

As I’ve said in the above comment that is expected

4 Likes

Do you have any screenshots or any examples to show how it displays incorrectly?

1 Like

I believe that the lesson is just training the student to be a creature of habit. the purpose is to teach code organizato when CSS is added to the HTML. thats the way im taking it. I like to think of it like chapters in a book- Introduction, title, chapters, sub-chapters, etc… your book will still have content and printabiity without these “sections” but its gonna look a terrible mess. So, like in HTML, having ways to organize our code with - ‘title’, ‘head’, ‘body’, ‘h1’, ‘p’, ‘div’, etc… is just a way to generate a method to the organized madness. dont think to much on it and just keep practicing repetition and it will all be okay.

7 Likes

good.
Your post is very good, thank you.
:nerd_face:

1 Like

Yeah, I don’t think these should be passing the ‘tests’. Already seen the tests pass with no closing tag. This isn’t helping beginners.

1 Like

This is misinformation. The tests shouldn’t be passing. If they’re teaching anything, it’s bad habits.

1 Like

As a Romanian, this is very funny :slight_smile:

1 Like

Content outside the body tag in HTML can still display because the HTML document is rendered as a whole, even if some elements are not properly nested within the body tag. However, it is generally considered best practice to keep all visible content within the body tag for proper structure and accessibility.

1 Like

Yeah, it’s displayed, but they can’t interconnect in the body or container section and sometimes we use other links outside the body.

i know exactly why
heres the correct way to hide something if this doesnt display the example properly on here <! this is an example of how to hide something to keep it from displaying in the - Pastebin.com
answer:
When you put an HTML element outside of the body tag, it is considered to be invalid HTML syntax. Browsers, however, will often try to correct invalid HTML by moving the element inside the body tag, which is why you may still see the

text displayed.

To hide the

text, you can use CSS to apply the “display: none;” property to the element. Here’s an example:

Hidden Paragraph Example .hidden { display: none; }

This paragraph is visible.

This paragraph is hidden.

In this example, the second

element has a class of “hidden” and is styled with CSS to have a display value of “none”, which will make it hidden when the page is rendered in the browser.

2 Likes

It is already explained in the NOTE in the INSTRUCTIONS section.
NOTE goes: Note : While some browsers may render some content outside body tags as well to accommodate the occasional mistake in your HTML, not all browsers do this! The best way to ensure that all your HTML renders the same way in all browsers is to ensure that your elements remain within the opening and closing body tags.

1 Like

It’s showing the tags in the browser because you’ve mistyped the tags: in your code you’ve added an extra space between the left angle bracket and the p, like this < p>.
In such a case (I tested it) it reads like ordinary text and not as tags.

In the course, it does not only state that; it also notes that: “While some browsers may render some content outside body tags as well to accommodate the occasional mistake in your HTML, not all browsers do this!” The browser “interprets and or infers” HTML. But to ensure that misinterpretation/errors don’t occur, it’s best practice to put all displayable content in the .

that statement was referring to that specific moment whereby you where instructed to write the p’s inside the body.

The body element is to indicate/give your code structure, to show that this certain code belongs to the “body” part of your code.