JavaScript Document title Property

Beginner
5 min read
Updated: Nov 2026
3 examples
Property

Definition

Document.title gets or sets the current title of the document (MDN). When present, it defaults to the text of the <title> element.

Read the notes below before you get or set this property. Prefer feature detection when support is limited.

Syntax

Use document.title. Start with this line.

JavaScript
document.title / document.title = "..."
CallWhat it does
document.title / document.title = "..."Primary signature.

Built into the browser. Read or assign document.title — no import required.

Library declarations
JavaScript
document.title / document.title = "..."

Parameters

ParameterDescription
String valueRequired. What the tab and <title> show

Return Value

Return ValueDescription
*The current value of document.title.

JavaScript Examples

Example 1 — Read document.title

Print the current page title (MDN pattern).

JavaScript
console.log(document.title);
// e.g. "Hello World!"
Try It Yourself

How It Works

  1. Access the property. No arguments — just read document.title.
  2. Get a string. Usually the text from <title> in <head>.
  3. Use it. Logging, analytics, or building a badge string.
  4. Empty string. Possible if the document has no meaningful title yet.

Example 2 — Set document.title

Assign a new string; the tab and <title> update together (MDN).

JavaScript
console.log("Before:", document.title);

document.title = "Goodbye World!";

console.log("After:", document.title);
console.log("Element:", document.querySelector("title").textContent);
Try It Yourself

How It Works

  1. Log before. Capture the original title for comparison.
  2. Assign a string. This is a normal property write.
  3. Tab updates. The browser shows the new title in the tab/window.
  4. DOM updates. The <title> text matches; if missing, one is created in <head> (MDN).

Example 3 — Unread Badge in the Tab

Prefix a saved base title with a count when there are unread items.

JavaScript
const baseTitle = "My App — Inbox";
let unread = 3;

function renderTitle() {
  document.title = unread > 0
    ? "(" + unread + ") " + baseTitle
    : baseTitle;
}

renderTitle();
console.log(document.title); // "(3) My App — Inbox"

unread = 0;
renderTitle();
console.log(document.title); // "My App — Inbox"
Try It Yourself

How It Works

  1. Keep a base title. Avoid stacking badges by rebuilding from a clean string.
  2. Build the display string. Prefix (n) only when unread > 0.
  3. Assign once. One write updates the tab and <title>.
  4. Clear when done. Set unread to 0 and restore the base title.

Browser Support

Document.title is a standard Document property. MDN marks it Baseline Widely available since July 2015 — safe for everyday use in modern browsers.

✓ Baseline Widely available

Document.title

Get/set the document title string — updates the tab and the title element in the DOM.

Wide Baseline
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Android WebView Supported · Modern WebView
Full support
title Widely available

Bottom line: Use document.title to read or change the page title. Prefer a descriptive HTML title for SEO; update with JS for SPAs, badges, and temporary status text.

Frequently Asked Questions

document.title gets or sets the document title string (MDN). Reading returns the title text. Assigning updates the tab/window title and the title element in the DOM.
No. MDN marks Document.title as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
Yes. MDN: assignment updates the title element text, or creates a title element in head if none exists.
They stay in sync when you use document.title. Prefer document.title for simple get/set; use the DOM when you need the element itself.
Yes. Set document.title when the view changes so the tab matches the current page. Pair with history.pushState for the URL.
Search engines use the document title as a primary topic signal. Prefer a clear title in HTML; update early with document.title for dynamic views.

Next: URL

Learn how to read the document URL string from JavaScript.

URL tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful