Element.insertAdjacentText() is an instance method that inserts a plain text node at one of four positions: beforebegin, afterbegin, beforeend, and afterend. Learn the MDN demo pattern, comparison with insertAdjacentHTML(), safe user-input handling, and five try-it labs aligned with MDN.
01
Kind
Instance method
02
Returns
undefined
03
Args
where + data
04
Creates
Text node
05
Safe
plain text
06
Status
Baseline widely
Fundamentals
Introduction
When you need to add words to the page — a username, a timestamp, or a chat message — you usually want plain text, not HTML markup. insertAdjacentText(where, data) creates a Text node from your string and places it at a precise position relative to an element.
MDN: given a relative position and a string, the method inserts a new text node at the given position relative to the element it is called from. The string is not parsed as HTML.
💡
Beginner tip
MDN recommends insertAdjacentText() or textContent when user-provided content should be plain text. Unlike insertAdjacentHTML(), angle brackets in the string are shown literally.
Element.insertAdjacentText() 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
Element.insertAdjacentText()
Insert plain text at beforebegin, afterbegin, beforeend, or afterend — returns undefined.
BaselineWidely available
Google ChromeSupported · Desktop & Mobile
Yes
Microsoft EdgeSupported · Chromium
Yes
Mozilla FirefoxSupported · Desktop & Mobile
Yes
Apple SafariSupported · macOS & iOS
Yes
OperaSupported · Modern versions
Yes
Internet ExplorerNot supported
No
insertAdjacentText()Excellent
Bottom line: Use insertAdjacentText() for safe plain-text insertion. Use insertAdjacentHTML() only when you need parsed markup.
Wrap Up
Conclusion
Element.insertAdjacentText() inserts a plain text node at one of four positions around a target element. It is the safe, beginner-friendly choice when you need words — not HTML markup — in a precise spot.
Use for user comments, labels, and timestamps (MDN)
Pick the right slot with the MDN position diagram
Prefer this over insertAdjacentHTML() for untrusted strings
Use afterbegin / beforeend inside containers
Combine with form input values for live text updates
❌ Don’t
Expect HTML tags to render (use insertAdjacentHTML instead)
Expect a return reference to the new text node
Use invalid where strings (throws per MDN)
Confuse with textContent (which replaces all text)
Use beforebegin on detached elements without a parent
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about Element.insertAdjacentText()
Plain text at four positions.
5
Core concepts
📝01
Returns
undefined
void
📄02
Input
plain
Text
📄03
Safe
user
MDN
✅04
Slots
4 pos
Same
⚡05
vs
HTML
Parse
❓ Frequently Asked Questions
It inserts a new text node at a position relative to the element (MDN). You pass a position string and plain text — the string is not parsed as HTML.
No. MDN marks Element.insertAdjacentText() as Baseline Widely available (across browsers since April 2018). It is not Deprecated, Experimental, or Non-standard.
Nothing useful — the return value is undefined (MDN).
insertAdjacentText() creates a Text node from a plain string. insertAdjacentHTML() parses HTML markup, which can be unsafe with user input (MDN).
beforebegin, afterbegin, beforeend, and afterend — the same four slots as insertAdjacentHTML() and insertAdjacentElement() (MDN).
MDN recommends it when user-provided content should be plain text, not HTML — for example comments, labels, or chat messages.
Did you know?
MDN: the existing text node inside an element is not replaced — further insertAdjacentText() calls create additional text nodes alongside it.