Skip to content
IT glossary
FrontendUpdated December 3, 2026

Virtual DOM

It’s an in-memory description of what a user interface should look like. A rendering library uses it to figure out which browser DOM nodes to keep, change, or replace.

Also known as: виртуальный DOM

A description, not a second web page

A virtual DOM is a tree of JavaScript objects that describes a UI. A node in this tree might say “render a button with this label and these children.” It isn't an actual button: it has no position on the screen and the browser doesn't paint it. Libraries such as React and Vue use this representation so that you can describe the UI for the current data instead of writing a separate set of DOM edits for every interaction.

From a state change to a DOM update

On an initial client render, the renderer uses the description to create DOM nodes. On an update, it can compare the new description with its previous representation of the UI; it doesn't need to walk the live DOM to reconstruct what it rendered last time. Matching elements and deciding what to preserve or replace is called reconciliation. Comparing descriptions to find differences is often called diffing. In React, the changes that result from this work are applied to the DOM in the commit phase.

Example: a button gets a new label

function SaveButton({ saving, onSave }) {
  return (
    <button disabled={saving} onClick={onSave}>
      {saving ? 'Saving…' : 'Save'}
    </button>
  );
}

When saving switches from false to true, React can call the component again. The result still describes a button in the same position, so React can keep the existing DOM node and change its disabled property and text. If the output were unchanged, React could run the component without modifying the DOM at all.

Identity matters in lists

Say a shopping list has an editable quantity field in each row. When the list is sorted, a stable key such as key={item.id} helps React match each row to the same item as before, even though it has moved. With an array index as the key, React matches rows by position instead. A row's local state can then stay in the same slot while the item shown in that slot changes. Keys need to be unique among siblings, not across the whole page.

What it does and doesn't optimize

A virtual DOM is not inherently faster than direct DOM updates. If you already know exactly which node needs a text change, setting textContent directly avoids the work of building and comparing UI descriptions. The benefit is that the renderer works out the edits for you as the interface changes. The browser still has its own work to do after DOM updates, which may include style calculation, layout, and paint.

How it comes up in interviews

Expect to explain why a component can render again without recreating its DOM nodes, or to predict what happens when a keyed list is reordered. A good answer distinguishes three things: the component producing a description, the renderer applying DOM changes, and the browser drawing the result.