This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
* Some parts of this feature may have varying levels of support.
The Text interface represents a text node in a DOM tree.
To understand what a text node is, consider the following document:
<html lang="en" class="e">
<head>
<title>Aliens?</title>
</head>
<body>
Why yes.
</body>
</html>
In that document, there are five text nodes, with the following contents:
"\n " (after the <head> start tag, a newline followed by four spaces)"Aliens?" (the contents of the title element)"\n " (after the </head> end tag, a newline followed by two spaces)"\n " (after the <body> start tag, a newline followed by two spaces)"\n Why yes.\n \n\n" (the contents of the body element)Each of those text nodes is an object that has the properties and methods documented in this article.
Text()Returns a new Text node with the parameter as its textual content.
Inherits properties from its parents, CharacterData, Node, and EventTarget.
Text.assignedSlot Read only
Returns a HTMLSlotElement representing the <slot> the node is inserted in.
Text.wholeText Read only
Returns a string containing the text of all Text nodes logically adjacent to this Node, concatenated in document order.
Inherits methods from its parent, CharacterData, Node, and EventTarget.
Text.splitTextBreaks the node into two nodes at a specified offset.
| Specification |
|---|
| DOM> # interface-text> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
Text |
29 | 16 | 24 | 16 | 8 | 29 | 24 | 16 | 8 | 2.0 | 4.4 | 8 |
Text |
1 | 12 | 1 | ≤12.1 | 1 | 18 | 4 | ≤12.1 | 1 | 1.0 | 1 | 1 |
assignedSlot |
53 | 79 | 63 | 40 | 10 | 53 | 63 | 41 | 10 | 6.0 | 53 | 10 |
getBoxQuads |
No | No | 31 | No | No | No | No | No | No | No | No | No |
splitText |
1Before Chrome 30, theoffset parameter was optional. |
12 | 1 | ≤12.1Before Opera 17, theoffset parameter was optional. |
1Theoffset parameter is optional. |
18Before Chrome Android 30, theoffset parameter was optional. |
4 | ≤12.1Before Opera 17, theoffset parameter was optional. |
1Theoffset parameter is optional. |
1.0Before Samsung Internet 2.0, theoffset parameter was optional. |
1Before version 4.4, theoffset parameter was optional. |
1Theoffset parameter is optional. |
wholeText |
2 | 12 | 3.5 | ≤12.1 | 4 | 18 | 4 | ≤12.1 | 3.2 | 1.0 | 4.4 | 3.2 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Text