CKTIS / JavaScript
ShadowRoot.append — adding nodes and text to a shadow tree
ShadowRoot.append adds nodes and text at the end of a shadow tree. It is inherited from DocumentFragment rather than a separate implementation. Learn how nodes move, fragments become empty, and appendChild() differs.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
shadowRoot.append(...nodesOrStrings);
fragment.append(...nodesOrStrings);ShadowRoot.append is the inherited DocumentFragment.append method: ShadowRoot extends DocumentFragment. Calling root.append(...) adds content after the shadow root's last child, not to the host element's ordinary children. An ordinary fragment instead serves to assemble a subtree before inserting it at its destination.
The method accepts multiple nodes and strings in argument order. Strings become Text nodes; they are not parsed as HTML. An existing node is moved, not copied. Passing an ordinary DocumentFragment moves its children and leaves the fragment empty; the fragment itself does not become a child of the root.
The result is undefined. Unlike append(), appendChild() accepts one node, does not directly support string arguments, and returns the added node or the emptied fragment. An invalid insertion, such as one creating a cycle, can throw a HierarchyRequestError DOMException.
This is a DOM API, not a feature of a particular ECMAScript edition. MDN marks DocumentFragment.append() as widely available across browsers since April 2018; using it on a shadow root also requires Shadow DOM support. The presence of Node 24 in a repository alone does not establish support for these browser APIs.
Examples
(() => {
const host = document.createElement("div");
const root = host.attachShadow({ mode: "open" });
const fragment = document.createDocumentFragment();
const label = document.createElement("strong");
label.textContent = "DOM";
fragment.append("Hello ", label);
const result = root.append(fragment, "!");
console.log(root.textContent);
console.log(root.childNodes.length);
console.log(fragment.childNodes.length);
console.log(label.parentNode === root);
console.log(host.childNodes.length);
console.log(result === undefined);
})();Result
Hello DOM! 3 0 true 0 true
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.