html: nesting
HTML elements inside one another
Perhaps read these first
You may find it helpful to read the following pages before this one.
- html
Nesting of HTML elements
HTML elements can be nested inside one another. For example:
<p>This food is <em>very</em> hot!</p>
That example has two HTML elements:
- An
em
element with contentvery
- A
p
element with content:This food is <em>very</em> hot
Element nesting creates a “parent/child” relationship”, as shown here:
- In this case, since this
em
element is contained entirely within thisp
element, we say that thep
element is the parent of theem
element. - Conversely, the
em
element shown here is the child of thep
element.
Exercises
-
How many elements do you see here, and what are they?
<div> This lesson about <b>HTML</b> is <em>very</em> interesting.</div>
-
In the example above, what is the parent of the
b
element? -
What relationship does the
em
element have to thediv
element?