Course contentsShow
← Web Development
Lesson 663 of 2,98212. The Document Object ModelFree lesson

The DOM Tree Structure

How browsers parse HTML into a hierarchical tree of nodes with parent-child relationships.

The DOM Tree Structure

You'll learn how browsers convert HTML markup into a living tree of interconnected nodes you can navigate and manipulate with JavaScript.

The Tree Metaphor

When a browser loads your HTML, it doesn't work with the raw text. Instead, it parses (reads and interprets) the HTML and builds a tree structure called the DOM tree. Think of it like a family tree or an organizational chart—every element has a parent above it and may have children below it.

How the Tree Forms

The browser starts at the <html> element (the root of the tree) and works downward. Each HTML tag becomes a node in the tree. Tags nested inside other tags become child nodes, and the outer tag becomes their parent node.

For example:

<html>
  <body>
    <h1>Hello</h1>
    <p>World</p>
  </body>
</html>

In the DOM tree:

  • <html> is the root
  • <body> is a child of <html> (and parent of <h1> and <p>)
  • <h1> and <p> are siblings (they share the same parent)
  • Even the text "Hello" and "World" are nodes—called text nodes

Parent-Child Relationships

Every node (except the root) has exactly one parent. Nodes can have zero, one, or many children. This hierarchical structure creates clear relationships:

  • Parent: the node directly above
  • Child: a node directly below
  • Sibling: nodes sharing the same parent
  • Ancestor: any node above (parent, grandparent, etc.)
  • Descendant: any node below (child, grandchild, etc.)

Key Takeaway: The DOM tree is a hierarchical map of parent-child relationships that the browser creates from your HTML, making every element navigable and accessible to JavaScript.