The Node.normalize() method cleans a node’s subtree so text is tidy: no empty #text nodes, and no adjacent text siblings. Learn the MDN before/after pattern, how it relates to textContent, and why MDN calls Text.splitText() its opposite.
01
Kind
Instance method
02
Params
None
03
Returns
undefined
04
Merges
Adjacent #text
05
Removes
Empty #text
06
Status
Baseline widely
Fundamentals
Introduction
On screen, "Hello" + " World" looks like one string. In the DOM, those can still be two separate text nodes sitting next to each other. Empty text nodes can also appear after edits.
normalize() walks the node and its descendants and fixes that: merge neighbors, drop empties. The visible text usually stays the same; the childNodes list becomes cleaner.
💡
Beginner tip
If you only care about the visible string, textContent or innerText is enough. Call normalize() when you care about the structure of text nodes themselves.
Concept
Understanding normalize()
MDN: puts the specified node and all of its sub-tree into a normalized form. In that form:
No empty text nodes remain in the subtree.
No adjacent text nodes remain—neighbors are merged into one.
In place — the method mutates the tree; it does not return a new node.
Recursive — nested elements’ text children are cleaned too.
Foundation
📝 Syntax
JavaScript
node.normalize();
Parameters
None.
Return value
None (undefined). The subtree is updated in place.
Node.normalize() is Baseline Widely available across modern browsers (MDN: since July 2015). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline · Widely available
Node.normalize()
Safe, long-standing DOM cleanup for text nodes in a subtree.
UniversalWidely available
Google ChromeFull support · Desktop & Mobile
Full support
Mozilla FirefoxFull support · Desktop & Mobile
Full support
Apple SafariFull support · macOS & iOS
Full support
Microsoft EdgeFull support · Chromium
Full support
OperaFull support · Modern versions
Full support
Internet ExplorerLong-standing support in legacy IE
Full support
normalize()Excellent
Bottom line: Merges adjacent text nodes and removes empty ones across the subtree.
Wrap Up
Conclusion
Node.normalize() tidies text in a subtree: merge adjacent #text nodes and remove empty ones. Use it when structure matters; use textContent when you only need the visible string. MDN’s opposite is Text.splitText().
Compare childNodes.length before and after when learning
Call it on a common ancestor to clean a whole subtree
Prefer textContent when only the string matters
Remember splitText as the opposite operation
❌ Don’t
Expect a return value—it mutates in place
Assume normalize changes element tags or attributes
Confuse DOM Node with the Node.js runtime
Skip normalize if your logic depends on separate text siblings
Forget empty text nodes also get removed
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about normalize()
Tidy text nodes without changing the readable string.
5
Core concepts
🔄01
Merges #text
neighbors
API
🗑️02
Drops empty
text nodes
Cleanup
🌳03
Whole subtree
recursive
Scope
⇄04
Opposite of
splitText
MDN
📄05
In place
no return
Mutate
❓ 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).
No. MDN marks Node.normalize() as Baseline Widely available (since July 2015). It is a standard DOM method — not Deprecated, Experimental, or Non-standard.
No. The method has no parameters and returns undefined (None on MDN). 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 back together (and drops empty ones).
Common causes include repeated appendChild(createTextNode(...)), insertBefore of text, or splitText. The visible string may look fine while childNodes still lists separate #text siblings.
Before walking childNodes/text node lists, after heavy DOM text edits, or when you need a tidy tree for serialization or equality checks that care about node structure.
Did you know?
MDN’s classic demo prints each child’s nodeName and nodeValue before and after. Watching two #text lines collapse into one is the clearest way to see that normalize changes structure, not the sentence the user reads.