document.append() inserts one or more Node objects or strings after the last child of the Document. Strings become Text nodes. On a normal loaded page, you usually want document.body.append() instead.
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax
Call document.append. Start with this line.
JavaScript
document.append(…nodesOrStrings)
Call
What it does
document.append(…nodesOrStrings)
Primary signature.
document.append(...)
Call with the arguments your case needs.
Built into the browser. Call append(...) on document — no import required.
Library declarations
JavaScript
document.append(…nodesOrStrings)
Parameters
Parameter
Description
param1…paramN
Required. Nodes and/or strings to insert
Return Value
Return Value
Description
*
Always undefined
JavaScript Examples
Example 1 — Append a Root to new Document()
MDN pattern: attach an <html> root to an empty document.
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
Create a paragraph. This is normal page content, not a document root.
Append to body. Pass a node and a string in one call.
String becomes text. The last child is a Text node with that string.
Why this path. On live pages, Element.append / body.append is the safe ParentNode append.
Compatibility
Browser Support
Document.append() is a browser DOM API marked Baseline Widely available on MDN (across browsers since April 2018).
✓ 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 Firefox89+
Yes
Apple Safari10+
Yes
Opera41+
Yes
Internet ExplorerNo
No
append()Excellent in browsers
Bottom line: Safe in modern browsers. On a loaded page prefer document.body.append(). See the MDN Document.append() reference.
Frequently Asked Questions
It inserts one or more Node objects or strings after the last child of the Document. Strings become Text nodes. The return value is undefined.
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, use document.body.append() (or Element.append) to add content. document.append() is mainly for attaching a root html or svg element to a new empty Document().
undefined. Check document.children or documentElement to verify what was added.
A live HTML document already has a root html element. Appending another one 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.