document.append() is an instance method from the ParentNode API. It inserts nodes or strings after the last child of the Document. Learn when to use it on a fresh new Document(), why it throws on a loaded page, how it compares to Element.append() and appendChild(), and five try-it labs.
01
Kind
Instance method
02
Inserts
After last child
03
Args
Nodes or strings
04
Returns
undefined
05
Live page
Use body
06
Status
Baseline
Fundamentals
Introduction
Every web page has a document object—the root of the DOM tree. Most tutorials teach you to add content with document.body.append(...) or document.getElementById("app").append(...). Document.append() is different: it appends directly to the Document node itself, not inside <body>.
MDN: Document.append() inserts a set of Node objects or strings after the last child of the document. Strings are inserted as equivalent Text nodes. To append to an arbitrary element in the tree, see Element.append().
💡
Beginner tip
On a normal loaded page, the document already has an <html> root. You usually update document.body or a container element—not document itself. MDN’s main use case is building a brand-new in-memory document with new Document().
param1, …, paramN — a set of Node objects or strings to insert (MDN).
Return value
None (undefined).
Exceptions
HierarchyRequestErrorDOMException — thrown when the node cannot be inserted at the specified point in the hierarchy (MDN).
Common patterns
JavaScript
// Build a new in-memory document (MDN)
const doc = new Document();
const html = doc.createElement("html");
doc.append(html);
// doc.children → HTMLCollection []
// On a live page — prefer body or a container
document.body.append("Hello");
document.getElementById("app").append(p, " ", span);
Compare
⚖️ Document.append vs Element.append vs appendChild
API
Appends to
Strings OK?
Typical use
document.append(...)
Document node
Yes
Root <html> on new Document()
document.body.append(...)
<body> element
Yes
Add UI on a live page
el.append(...)
Any element
Yes
General DOM updates
parent.appendChild(node)
Any parent node
No (Node only)
Classic single-child insert
Cheat Sheet
⚡ Quick Reference
Goal
Code / note
Root on new Document
doc.append(doc.createElement("html"))
Update live page content
document.body.append(...)
Append text
el.append("Hello")
Append several items
el.append(a, " ", b)
Return value
undefined
MDN status
Baseline Widely available (Apr 2018)
Snapshot
🔍 At a Glance
Four facts about document.append().
Call
document.append
Instance
Returns
undefined
MDN
Live page
use body
Not doc
Status
baseline
Apr 2018
Compare
📋 Document.append() vs Element.append()
document.append(...)
element.append(...)
Receives on
Document root
Any Element
Main use
New Document() root
Everyday DOM updates
Live HTML page
Second <html> fails
Works on body, div, etc.
Syntax & strings
Same ParentNode API
Same ParentNode API
Hands-On
Examples Gallery
Examples follow MDN Document: append(). Start with a fresh Document(), then see what happens on a live page.
📚 Getting Started
MDN’s core examples: build a document root and avoid invalid trees.
Example 1 — Append a root <html> to new Document()
MDN: when creating a new document without any existing element, append a root HTML element.
JavaScript
const doc = new Document();
const html = doc.createElement("html");
doc.append(html);
console.log(doc.children.length); // 1
console.log(doc.documentElement === html); // true
MDN: the operation would yield an incorrect node tree. Use document.body.append() instead for page content.
📈 Practical Patterns
What to use on a loaded page and how ParentNode helpers compare.
Example 3 — Use document.body.append() on a live page
Add content where beginners expect—inside <body>.
JavaScript
const p = document.createElement("p");
p.textContent = "Added to the page";
document.body.append(p);
// Same ParentNode API as document.append, different target
Document.append() is Baseline Widely available (MDN: across browsers since April 2018). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline Widely available
Document.append()
ParentNode append on Document — build roots on new Document(), use body.append on live pages.
BaselineWidely available
Google Chrome54+
Yes
Microsoft Edge17+
Yes
Mozilla Firefox48+
Yes
Apple Safari10+
Yes
Opera41+
Yes
Internet ExplorerNo
No
append()100% supported
Bottom line: Use document.append() to attach a root element to a new Document(). On a loaded page, prefer document.body.append() or Element.append().
Wrap Up
Conclusion
document.append() inserts nodes or strings after the last child of the Document. MDN’s key lesson: use it to attach a root <html> or <svg> to a new empty document; on a live page, update document.body or specific elements instead.
Document-level ParentNode append—roots on new docs, body on live pages.
5
Core concepts
📝01
Kind
instance
document.
🗂02
Target
Document
MDN
🔗03
Live page
use body
Tip
✓04
Returns
undefined
ParentNode
🛡05
Status
baseline
2018
❓ Frequently Asked Questions
It inserts one or more Node objects or strings after the last child of the Document. Strings become Text nodes (MDN).
No. MDN marks Document.append() as Baseline Widely available (across browsers since April 2018). It is not Deprecated, Experimental, or Non-standard.
On a loaded HTML page, the document already has a root html element, so use document.body.append() or document.documentElement.append() to add content. document.append() is mainly for building a new empty Document() with a root html or svg element (MDN).
Nothing useful — the return value is undefined. Check document.children or childNodes to verify what was added.
MDN: appending a second html element to an existing HTML document throws HierarchyRequestError because the tree would be invalid.
append() accepts multiple nodes and strings and returns undefined. appendChild() accepts one Node and returns that child.
Did you know?
MDN notes that Document.append() and Element.append() share the same ParentNode specification—but on a normal web page you almost always call append on an element, not on document itself.