The Element.prepend() method inserts one or more nodes or strings before the first child of the element (MDN). Strings become Text nodes. It returns undefined.
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax
Call el.prepend. Start with this line.
JavaScript
el.prepend(node1, node2, …)
Call
What it does
el.prepend(node1, node2, …)
Primary signature.
el.prepend(...)
Call with the arguments your case needs.
Built into the browser. Call prepend(...) on an Element — no import required.
Library declarations
JavaScript
el.prepend(node1, node2, …)
Parameters
Parameter
Description
Parent element
Required. Receives the new first children
param1…paramN
Required. Node objects and/or strings
Return Value
Return Value
Description
*
Always undefined
JavaScript Examples
Example 1 — Prepend an Element (MDN)
Append a paragraph, then prepend a span so the span lands first.
Pass several items. Nodes and strings can mix in one call.
Keep argument order. First argument is the first of the new bits.
They land at the start of the parent’s child list.
Verify. Parent HTML shows text, then the paragraph.
Compatibility
Browser Support
Element.prepend() is Baseline Widely available on MDN (across browsers since April 2018). It is not Deprecated, Experimental, or Non-standard. Prefer it over insertBefore when you need strings or multiple nodes at the start.
✓ Baseline Widely available
Element.prepend()
Modern ParentNode insert — nodes or strings before the first child. Widely supported since 2018.
2018+Widely available
Google Chrome54+
Supported
Mozilla Firefox49+
Supported
Apple Safari10+
Supported
Microsoft Edge17+
Supported
Opera41+
Supported
Internet ExplorerNot supported — use insertBefore
Unavailable
prepend()Baseline
Bottom line: Safe for modern browsers. For very old IE, use insertBefore(node, parent.firstChild).
Frequently Asked Questions
MDN: it inserts one or more Node objects or strings before the first child of the element. Strings are inserted as equivalent Text nodes.
No. MDN marks Element.prepend() as Baseline Widely available (across browsers since April 2018). It is not Deprecated, Experimental, or Non-standard.
prepend() inserts before the first child; append() inserts after the last child. Both accept multiple nodes and strings and return undefined.
Nothing useful — the return value is undefined (MDN). Inspect childNodes or textContent to verify what was added.
Yes. Pass a string: el.prepend("Headline: "). The browser creates a Text node for you (MDN).
Like append, prepend moves the node to the new position. Use cloneNode() if you need a copy.