What is the point of nesting the <p> element in a <div> element?


In steps 1 and 2 of this exercise, both <p> elements display in the same exact way. As it doesn’t seem like anything special happened here, what is the point of nesting the <p> element in a <div> element?


In this case, this is done purely for demonstrative purpose. In the future you will find that <div> elements are often used to group related content. This can serve to give a page some added structure and to allow for more modular styling.


It is primarily for the content creator and used to distinguish between paragraphs and sets of content.


Can we use the div element in the following way?


If we cannot use it then please explain why


no, as we can see in the documentation:


body must a child of html, the documentation shows the Permitted content and Permitted parents.


I’m just setting out on learning this myself, but if I’m right, I’d say this is done because a body can have multiple divisions, but divisions cannot have multiple bodies and therefore the multiple divisions must be contained within the body.


everything in the body is whats being shown on the screen on the webpage so having divisions in the inside would make sense right ?


There is a hierarchy of tags in html. The html tag itself is the overall ‘parent’ tag. Followed by:
head which is the header section of the page and then the body that includes everything else. Divs are inside the body tags.


When treated as having meaning, writing a number of paragraphs in a division is a way of telling the source reader that they are all grouped together. We don’t send a baker’s dozen out in the customer’s hands, we place them in a box, with wax paper between the layers so the frosting doesn’t stick to the paper.

Think back to what we learned about writing and outlining of essays going back to grade 8, and how that same process applied all the way through secondary and even tertiary education. HTML is a document just like that essay and the better we outline it, the easier it will be to interpret the source, and eventually present (which is a totally separate concern) the content. We give meaning to the content by how we structure it.



Since head and body are siblings, is it correct to write:

<head>Hello World</head>


<p>This is a page that.... etc</p> 


skipping totally <div> that was there for demo reasons?


No, it is not. HEAD is not a content container. It is reserved for meta data that is not visible to the visitor. All page content belongs in the BODY.

The only visible content in the HEAD is the <title>Hello World</title> which appears in the window’s title bar, or tab, not on the page itself.

The HEAD is where we declare things like what is the document type and root element? What is the human readable language used in the document? What is the character encoding so user agents can parse correctly? What background resources are needed in the parsing and page draw processes and how do they relate to the page? What is the title of the page (already mentioned)? What special cataloging information is required for this document?

<DOCTYPE html>

The above tells a user agent that this has an HTML5 document type, with the root element being, <html></html>.

<html lang="en">

The above tells the user agent that the human readable language is English.

  <meta charset="UTF-8">
  <title>Hello World</title>
  <link rel="stylesheet" href="styles.css">
  <link rel="author" href="http://www.example.com">

Above we declare character encoding as UTF-8, the de facto standard adopted by the international web community. It is before the title so that any special characters are recognized and printable. We describe the relation and location of the external resource needed by this document; and, lastly we insert a link to the author’s own page or site. Not required, as such, but I included it as an example for rel, the relation attribute.

As for writing paragraphs directly into the BODY, that may be valid but it is not organized and can be wieldly to work with when it comes to presentation. Having page sections with their own containers makes short work of this, and makes the document easier to read and analyze (by search engines, for example).


I clarified a lot of things with the details that you covered Roy.
Μany, many thanks for your reply!


Errata: The doctype is not in the head, d’oh! And neither is the root element, <html> they can be seen above as being at the very start of the document, though.


OK, thanks for checking on this.


i always though that the point of using the <p></p> was for spacing sentances and or using it to imput words

1 Like

Markup is for documenting content, not for spacing or presentation.


ohh woops thanks for correcting me


This is pretty late response, but i just want to say that was the best explanation i have ever read thank you !


Well said. It’s just like how the human body has multiple divisions: the digits (fingers and toes), the appendages (arms and legs), and the torso.

1 Like

A more appropriate analalogy would be a tree which can have only one root, and one trunk. It can have many branches, both off the trunk and off the branches themselves. The content (text nodes) would be the leaves.


why do we use the div element and do we need it

1 Like