The Text interface represents a text node in a DOM tree.

EventTarget Node CharacterData Text

To understand what a text node is, consider the following document:

<html lang="en" class="e">
    Why yes.

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.



Returns a new Text node with the parameter as its textual content.

Instance properties

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.

Instance methods

Inherits methods from its parent, CharacterData, Node, and EventTarget.


Breaks the node into two nodes at a specified offset.


DOM Standard
# interface-text

Browser compatibility

BCD tables only load in the browser

See also