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> </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>‎</title>
. Alternatively, you could use document.title='\u200E'
in JavaScript.