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
Inside the body element, create an h1 element with a heading, for example Hello world!. The h1 element will be a child of body.
Below the h1 element, create its sibling: a p element with a sentence, for example This is my first web page.
Start programming for free
6/8