Nesting and Family Relationships
Let's look at the page we have built so far:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>My First Page</title>
</head>
<body>
</body>
</html>Some elements are inside other elements: head and body are inside html, and meta and title are inside head. Remember that the content of an element can be other elements. When we put an element inside another one, we say that we nest it.
To describe how nested elements relate to each other, we borrow words from the family:
- A parent is the element that another element is directly inside.
htmlis the parent ofheadandbody. - A child is an element directly inside another element.
titleis a child ofhead. - Siblings are elements with the same parent.
headandbodyare siblings, and so aremetaandtitle.
Now let's give body some children, so that something finally shows up on our page. Besides the h1 heading, we'll use the p element, which stands for paragraph. We'll look at paragraphs more closely in the next lesson.
Instructions
- 1
Inside the
bodyelement, create anh1element with a heading, for exampleHello world!. Theh1element will be a child ofbody. - 2
Below the
h1element, create its sibling: apelement with a sentence, for exampleThis is my first web page.