Keep a base title. Avoid stacking badges by rebuilding from a clean string.
Build the display string. Prefix (n) only when unread > 0.
Assign once. One write updates the tab and <title>.
Clear when done. Set unread to 0 and restore the base title.
Compatibility
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.
WideBaseline
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
Android WebViewSupported · Modern WebView
Full support
titleWidely 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.