Call it on a parent (or any ancestor) after text edits that may leave empty or adjacent #text nodes.
Build or edit the subtree (append text nodes, splitText, etc.).
Call node.normalize() on the container (or a higher ancestor).
Walk childNodes — adjacent text siblings are gone.
Remember: no return value; the tree is updated in place.
Piece
Required?
Role
Receiver node
Yes
Root of the subtree to clean
Parameters
None
—
Return value
—
undefined (mutates in place)
Pseudocode
Pseudocode
for each descendant under node (depth-first):
remove empty text nodes
if two #text siblings are next to each other:
merge into one text node
result: tidy subtree, same visible text
Reference
Cheat Sheet
Keep these facts handy when cleaning up DOM text structure.
Topic
Detail
Syntax
node.normalize()
Scope
Node + entire subtree
Merges
Adjacent #text siblings
Removes
Empty text nodes
Returns
undefined
Opposite
Text.splitText()
Elements / comments
Not merged (only text adjacency)
Status (MDN)
Baseline Widely available
Try it
Live Preview
Build adjacent text nodes, empty text, or a nested case — then call normalize() and list the children (MDN-style).
Browser demo of Node.normalize() — merge adjacent text, drop empty text.
Result
Loading…
Code
JavaScript Examples
Short, copy-ready snippets. Open DevTools Console, or use Try It Yourself for a live editor.
Scope: whole subtree — call on a local parent when possible.
One line:normalize() cleans text-node clutter — merge neighbors, remove empties, keep the readable string.
Frequently Asked Questions
It puts the node and its entire subtree into a normalized form: no empty text nodes, and no adjacent text nodes (adjacent ones are merged) (MDN).
No. MDN marks it Baseline Widely available (since about July 2015). It is not Deprecated, Experimental, or Non-standard.
No. It has no parameters and returns undefined. It mutates the subtree in place.
MDN lists Text.splitText() as its opposite. splitText breaks one text node into two; normalize merges adjacent text nodes and drops empty ones.
Repeated appendChild(createTextNode(...)), insertBefore of text, or splitText. The visible string may look fine while childNodes still lists separate #text siblings.
Before walking childNodes carefully, after heavy text edits, or when you need a tidy tree for structure-sensitive checks.