Parent element and child element

Hi, I am fairly new to coding and was wondering what a parent and child element were in html?

HTML is written as trees of elements. By tree, I mean something which looks like this:

      |    |
      b    c
      |    |
     ———  ———
     | |  | |
     d e  f g

(re why it’s called a tree, if you look at it upside down, it kinda looks like a tree)

So like an example of a valid HTML document:

    <title>I'm an HTML page!</title>
    <meta name="description" content="Just an example of HTML" />
    <p>Just a bit of text here.</p>

So within the html element are two elements, head and body. Within the head element are two elements, title and meta. Within the body element are two elements, h1 and p.

head and body are children of html. html is the parent of head and body. title and meta are children of head. head is the parent of title and meta. h1 and p are children of body. body is the parent of h1 and p.

An element can have many children. An element always has one parent unless it’s the <html> element, which is the root of the tree.

parent is the element which contains another element, children is the contained element. A child element can also have nested elements inside it, making it a parent element to its nested elements. Very often child elements behavior/appearance is influenced by their parent settings.

Thank you so much for the clarification!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.