Favorites

DOM Node.textContent Property

☕
Enjoying this site?

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

Buy us a coffee
Node.textContent
DOM Node PropertyThis property is supported by all modern browsers.
Updated 28th November 2026

The textContent property gets or sets the text inside a node and its descendants. Setting it is the safe way to insert text, because HTML in it isn't parsed.

Description

The textContent property returns the text content of a node and all its descendants, joined together, including text inside <script> and hidden elements. Setting it removes all children and inserts a single text node.

Because the value is treated as plain text, setting textContent is the safe way to show user-supplied text: any HTML in it appears literally instead of being run. It's also faster than innerHTML and innerText, since it doesn't involve parsing or layout.

For the document itself, textContent is null; use document.documentElement.textContent instead. Reading it from a large element returns all its text in one string, including white space from the HTML source, so trim() the result when comparing it.

Syntax

node.textContent
node.textContent = text

Value

A string containing the text of the node and all its descendants. Setting it replaces all children with a single text node.

Example

<div id="box">Hello <strong>world</strong><span hidden> (hidden)</span></div>
const box = document.getElementById('box');
console.log(box.textContent);
box.textContent = '<b>Not bold</b> - shown as text';
console.log(box.innerHTML);

Browser Support

The following information will show you the current browser support for the Node.textContent property. Hover over a browser icon to see the version that first introduced support for this property.

This property 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