subtree
A node together with everything below it, which is itself a tree.
In more detail
Every node in a tree is the root of its own subtree, so operations on a whole branch can treat it as a smaller tree. In a web page, the subtree of an element is that element plus everything nested inside it.
Examples
CSS custom properties are inherited by every element in a subtree, so setting data-theme on a section themes only that section.The inert attribute disables an element's whole subtree.In the browser: Removing an element removes its whole subtree. A MutationObserver with subtree: true watches every descendant, not just direct children.Related terms
- tree — A hierarchy of nodes joined by edges, with one root at the top, no cycles, and exactly one path between any two nodes.
- recursion — A technique where a function solves a problem by calling itself on a smaller version of the same problem.
- BST property — The rule that keeps a binary search tree searchable: left subtree keys are smaller than the node, right subtree keys are larger.
- DOM — The tree of objects a browser builds from a web page, which scripts read and change to update what is on screen.
- CSS custom property — A value you name yourself in CSS, such as --color-primary: #2563eb, and use elsewhere with var(--color-primary).
- inert attribute — An HTML attribute that makes an element and everything inside it unclickable, unfocusable and hidden from assistive technology.
- DOM node — One object in the DOM tree, such as an element, a run of text or a comment.
- descendant — Any node below a given node in the DOM tree: its children, their children and so on.
- MutationObserver — A browser object that watches part of the DOM and reports changes, such as added nodes or changed attributes, in batches.
- diffing algorithm — The rules React uses to compare an old element tree with a new one and find what changed.
- unmount — When React removes a component and its DOM nodes from the page, discarding its state.
- component identity — How React decides that a component in the new render is the same one as before, so it keeps its state.
Taught in
- Binary Trees And Their Traversals — Algorithms & Data Structures for Working Engineers
- Binary Search Trees: Search, Insert And Delete — Algorithms & Data Structures for Working Engineers
- AVL Trees: Rotations That Keep The Guarantee — Algorithms & Data Structures for Working Engineers
- Backtracking: Search With Pruning — Algorithms & Data Structures for Working Engineers
- CSS Custom Properties & Dynamic Theming Architecture — Design Systems & Component Engineering
- HTML Parsing, Tokenization And The Document Object Model (DOM) — Frontend Architecture & Web Platform
- DOM Manipulation: DocumentFragment And HTML Templates — Frontend Architecture & Web Platform
- MutationObserver: Reactive DOM Watching Without Polling — Frontend Architecture & Web Platform
- Memory Management: Garbage Collection, Memory Leaks And WeakMap — Frontend Architecture & Web Platform
- Virtual DOM vs Real DOM: The Reconciliation Cost Model — React 19 & Modern Component Architecture
- Keys In Depth: Identity Preservation And Identity Resetting — React 19 & Modern Component Architecture
- Diffing Algorithm: Element Type Shifts And Subtree Tear Down — React 19 & Modern Component Architecture
- SyntheticEvent System: Event Delegation in Modern React — React 19 & Modern Component Architecture
- useEffect Lifecycle: Mount, Dependencies, And Cleanup Phases — React 19 & Modern Component Architecture
- Lifting State Up: Colocation, Ownership, And Data Flow — React 19 & Modern Component Architecture
- useContext in Depth: Scoping, Consumer Subscription Costs — React 19 & Modern Component Architecture
- useSyncExternalStore: Tearing-Free Store Subscriptions — React 19 & Modern Component Architecture
- Creating Event Listener Hooks with Clean Teardown Logic — React 19 & Modern Component Architecture
- Suspense Architecture: Promises, Fallbacks, And Co-ordination — React 19 & Modern Component Architecture