I added <body> to my page as instructed but I am not passing step one. Why?


#1

Question

I added <body> to my page as instructed in this exercise but I am not passing step one. Why?

Answer

Be sure to create both an opening tag (<body>) and a closing tag (</body>) for this element. Take another careful look at the code snippet on display in this lesson. Notice how both the opening and closing body tags are nested within the html tags? Notice how indentation is being used here? You are going to want to follow suit.


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

would an opening tag (<p>) and a closing tag (</p) be always be display this way and why? …why is it says <body> when its really<p>?


#3

The BODY element is the outermost container of the content portion of the document. The P element is content nested in the body, as it should be. A valid HTML document has only one BODY, but has no limit on content.

<body>
  <p>This is page content (a paragraph) nested in the BODY element.</p>
</body>

#4

Thanks! I finally understood this once I moved along the lesson :slight_smile:


#5

What is the standard indentation for nesting? In this case for the p tag under the body tag?


#6

Because there is a lot of nesting in typical HTML document, the accepted standard is two spaces per level.

<body>
  <div>
    <hi></h1>
    <div>
      <p></p>
      <p></p>
      <p></p>
    </div>
  </div>
</body>

#7

It still wont work for me. What am I doing wrong?


#8

Link to lesson, please, as well, post your HTML so we can test it.


#9

Hi, why do we have to use both opening and closing tags, < body>,</ body>,< p> and </ p>, for displaying content? I tried it without the body tags and the content still displays on the webpage. What’s the difference between the two tags?


#10

This question goes against the grain of well-formedness in documents facing the web. There are some rare instances where closing tags are not mandatory, but on the whole, our documents should follow strict guidelines and use closing tags where expected.

Take for instance list items and paragraphs.

<section>
  <ul>
    <li>list item
    <li>list item
    <li>list item
    <li>list item
  </ul>
</section>

List items are easy to separate using only the OPENTAG, but in the above, the </ul> and </section> ENDTAGs must be present or the document will not validate. LIkewise,

<section>
  <h1>heading</h1>
  <p>Lorem ipsum
  <p>Lorem ipsum
  <p>Lorem ipsum
  <p>Lorem ipsum
</section>

paragraphs are also easily distinguished by their OPENTAG. Again, the </h1> and </section> ENDTAGs are required or the document will not validate.

Loose paragraphs and list items may be okay, but in the fast changing world we should never take for granted that every user agent will be forgiving of missing endtags. If the spec calls for it, then use it, without question and you will get less surprises in future.


#11

A post was split to a new topic: Why no error?