Favorites

DOM Element.prepend() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Element.prepend()
DOM Element MethodThis method is supported by all modern browsers.
Updated 28th November 2026

The prepend() method adds one or more nodes or text strings at the start of an element, before its first child.

Description

The prepend() method inserts nodes or strings before the first child of the element. Like append(), it accepts several arguments and treats strings as text.

The arguments are inserted in the order given, so el.prepend(a, b) puts a first and b straight after it, before any existing children. Strings are inserted as text nodes, never parsed as HTML.

If a node you prepend is already in the document, it's moved rather than copied. To insert at a position in the middle, use before() or after() on a sibling, or insertBefore() on the parent.

Syntax

element.prepend(param1, param2, ...)

Parameters

  • param1, param2, ...Nodes or strings to add at the start.

Return Value

None (undefined).

Example

<ul id="list">
  <li>Old first item</li>
</ul>
const list = document.getElementById('list');
const li = document.createElement('li');
li.textContent = 'New first item';
list.prepend(li);
console.log(list.firstElementChild.textContent);

Browser Support

The following information will show you the current browser support for the Element.prepend() method. Hover over a browser icon to see the version that first introduced support for this method.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee