Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Document.title — reading and changing the document title

Document.title reads and sets a document's title. Reading it normalizes ASCII whitespace.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

document.title;
document.title = "New title";

Document.title is a writable Web API property, not an ECMAScript function. Use document.title for reading and assignment.

In HTML, it uses the first title element in tree order. Reading trims ASCII whitespace and collapses its runs to single spaces; a missing title yields "".

Assignment replaces text, without parsing HTML. If title is missing, it creates one in head; with neither element, nothing changes.

For a document rooted at SVG svg, it uses the first direct SVG title child, creating it on assignment if missing. The example requires a browser environment.

Examples

const doc = document.implementation.createHTMLDocument("");
doc.title = "  Learning\n  JavaScript  ";
console.log(JSON.stringify(doc.title));

Result

"Learning JavaScript"

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources