I've searched for the definition of a "node" in a programming language and I am still finding it hard to understand.

Could anyone advice me in simple, layman's terms:

What is a node?


4 Answers 4


Etymologically, a "node" is a "knot": think of a fisherman's net as "holes tied together with string", and then nodes are where the string is knotted. The term comes from graph theory in mathematics. If you think of a graph as a collection of points connected to each other by lines ("arcs"), then the points are called nodes. A tree is a special case of a graph in which a node can only have one "upwards" arc (to its "parent"). The DOM models a document as a tree: documents have a hierarchic structure in which sections contains sections contain sections, and a tree is a graph-theoretic representation of a hierarchy. So the parts of a document - the sections - are represented by nodes in the tree.


In the context of an SGML language where DOM is typically used (i.e. HTML, XML), a node is the smallest piece of text that has semantic meaning. Nodes are arranged in a tree structure, with the document as the root node. Each node can have zero or more children.

There are several types of nodes:

  • Document: this is the root node of the whole document. It represents the root of the SGML tree, one step above the root element (e.g. the <html> tag). This is done so it can contain metadata such as the DOCTYPE.
  • Element: this is a "tag" e.g. <div> or <MyXmlElement>. Elements can have subnodes, including attributes and other elements.
  • Attribute: This is one key/value pair inside an element. For example, the class specifier: <div class="SomeCssClass">
  • CDATA: "loose" text: <div>This CDATA is a child of the div element.</div>

You can safely compare it to a map of a subway system, e.g. the London Underground:

London Underground Map (http://it.wikipedia.org/wiki/Mappa_della_metropolitana_di_Londra)

A node is a stop, an edge is the connection between stations. That's about it with general graphs. However, there are special graphs with more, interesting properties, like Trees:

a Tree (https://hbfs.wordpress.com/2013/05/14/average-node-depth-in-a-full-tree/)

Nodes in a tree are either (a) the root (think <html>) or (b) have exactly one parent. They may also have one or many children nodes, which have them as a parent, so we get exactly one path to the root for every node in the graph.

The DOM is a tree.


The Node object represents a single node in the document tree.

A node can be an element node, an attribute node, a text node, or any other of the node types explained in the Node Types chapter.

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.