HTMLTitleElement: text property - Web APIs | MDN

Value

A string.

Examples

Consider the example below:

html

<!doctype html>
<html lang="en-US">
  <head>
    <title>
      Hello world! <span class="highlight">Isn't this wonderful</span> really?
    </title>
  </head>
  <body></body>
</html>

js

const title = document.querySelector("title");
console.log(title.text); // "Hello world! <span class="highlight">Isn't this wonderful</span> really?"
title.text = "Update the title";

As you can see, the span tag remained unparsed; the <title> element's contents were treated as plain text and returned exactly as they appear in the title element.

Specifications

Specification
HTML
# dom-title-text-dev

Browser compatibility

Help improve MDN

Learn how to contribute

This page was last modified on by MDN contributors.