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?


#12

My problem: Not the code itself, but the fact that I had not pressed “Run” yet.


#13

If given enough time to time-out, the lesson auto-runs when we resume coding. That is a big time fly in the ointment as many members will contend, and one we have long been requesting would be rectified.

Reset the lesson, and do it again would be my advice.


#14

A valid HTML document has only one BODY, but has no limit on content.

Ref to your above message , I am revising this course (doing it all over again) and closer to the end I do recollect noticing how more than 1 BODY are created in a single HTML document with the intent to separate long codes- or rather break down long complicated data

Please do clarify on this


#15

https://dev.w3.org/html5/html-author/#the-body-element

4.3.4.1 The body element

The body element represents the main content of the document.

Start tag: optional
End tag: optional

Categories: Sectioning root.

Contained By: As the second element in an html element.

Content Model: Flow content.

The operative term is bolded. There is no second, ‘second element’.

That stipulation aside, it is possible to have two body elements if there are two html elements. This is done in an <iframe></iframe> element. Use the link above to search the site for that element and see how an html document can contain another html document.

The learning environment of the main CC site is a perfect example of this. Our webpage (the one we see) is actually embedded in another webpage, the one with a single URL. The embedded page has our token in the URL and can only be reached internally on CC’s servers. That’s an approximation, at least. The key is the iframe.


#16

sorry but my knowledge of computing is rather basic…I did not follow what you being said


#17
<html>
  <head>
              < first element (metadata)
  </head>
  <body>
              < second element (main content)
  </body>
</html>

#18

great…much simpler now
thank you for your assistance…:slight_smile:


#21