Skip to content

Virtual DOM

In one line

The Virtual DOM is a lightweight in-memory representation of the real DOM that React uses to calculate the minimal set of changes before touching the browser.

In simple words

The Virtual DOM (VDOM) is a JavaScript object tree that mirrors the real DOM. When your component's state or props change, React builds a new virtual DOM tree from the updated JSX. It then compares this new tree to the previous one — a process called diffing or reconciliation — and computes the exact set of DOM mutations needed.

This is faster than directly manipulating the real DOM because reading and writing the real DOM is slow (it triggers layout recalculations). React batches the computed changes and applies them all at once, minimizing browser reflows.

You rarely interact with the Virtual DOM directly. It is an implementation detail that makes React's declarative model practical: you describe the desired UI, and React figures out the most efficient way to update the real DOM to match.

Example

jsx
// When state changes, React creates a new VDOM tree:
// Old:  <div><h1>Hello</h1></div>
// New:  <div><h1>World</h1></div>
// React diffs the two trees and only updates the text node,
// not the entire <div> or <h1>.

React compares old and new virtual DOM trees, finds that only the text content changed, and updates just that one text node in the real DOM.

Common confusions

  • Confused with: real dom

    The difference: The real DOM is the browser's live, heavy object model. The Virtual DOM is a lightweight JS copy React maintains in memory. React updates the real DOM only after diffing the virtual one.

Related terms

Related Resources

Related Lessons

  • React Overview

    Learn about the Virtual DOM and React's core philosophy.

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary