Question

I'm using

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8"/>
    <script>document.title=" ";</script>
  </head>
</html>

It works in IE and Firefox, but Chrome doesn't work. Well, in W3C standard. It seems that blank title is not allowed?!

User agents should use the document's title when referring to the document in their user interface. When the contents of a title element are used in this way, the directionality of that title element should be used to set the directionality of the document's title in the user interface.

Was it helpful?

Solution

According to HTML5 CR, the title element is required, unless “the document is an iframe srcdoc document or if title information is available from a higher-level protocol” (this is specified in the description of the head element).

It is possible to set the title in JavaScript by an assignment to document.title, in practice and according to HTML5 CR. Of course, this is ineffective for many important uses of the title, since this only takes place in a browser.

HTML5 CR also specifies that the title element must not be empty or contain just a space. More exactly, the content must be text that is not inter-element whitespace.

There is no corresponding requirement for the value of document.title. However, HTML5 specifies that on assignment, leading and trailing whitespace is stripped off. If you test the value of document.title after the assignment document.title = " ", you will see that the value is the empty string, not a space.

Browsers differ in what they do with the document title (set with a <title> element or via assignment to document.title). They may display it in various ways in their user interface. If the title is set to the empty string or is not set at all, browsers typicallty use the file name of the document, possibly somehow modified, in place of a title. This is what happens e.g. in Chrome, Firefox, and IE (on Windows) when they show document title as the name of a tab. (I don’t know what the question means by saying that setting title blank “works” in IE and Chrome.)

In most cases, an empty title for a document makes no sense, any more than it would make sense to publish a book without a name. But if you have a use case where you want to make the title (as shown by browsers in some contexts), you can deploy various tricks.

For example, NO-BREAK SPACE U+00A0 is by definition not a whitespace character in HTML, so you could use <title>&nbsp;</title> in HTML or document.title='\u00A0' in JavaScript. The title will then look like blank, but it’s technically not empty, so it will be used browsers.

Since NO-BREAK still occupies space (it’s really shown with a glyph, just a completely blank glyph), you might use LEFT-TO-RIGHT MARK U+200E instead; it is an invisible (zero-width) control character. In HTML, you could use <title>&lrm;</title>. Alternatively, you could use document.title='\u200E' in JavaScript.

OTHER TIPS

chrome 76, macos 13 may 2019:

<title>&lrm;</title>

works, and here is a full example for an empty jekyll page with no tab title:

---
layout: null
---

<link href="http://localhostdotdev.com/favicon.ico" rel="icon" type="image/x-icon" />
<title>&lrm;</title>
<style>body { background-color: rgb(40, 44, 47) }</style>

(also has an empty favicon and a dark background that matches chrome's dark mode)

no title no favicon tab chrome

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top