HTMLTitleElement: text property
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The text
property of the HTMLTitleElement
interface represents the child text content of the document's title as a string. It contains the <title>
element's content as text; if HTML tags are included within the <title>
element, they are included as part of the string value rather than being parsed as HTML.
Setting a value for the text
property replaces the entire text contents of the <title>
.
Value
A string.
Examples
Consider the example below:
<!doctype html>
<html lang="en-US">
<head>
<title>
Hello world! <span class="highlight">Isn't this wonderful</span> really?
</title>
</head>
<body></body>
</html>
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
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
text |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support