Is it allowed to use other tags inside <title>?
Asked Answered
W

4

15

Is it correct practice or valid syntax to use other tags inside a <title>?

An example for multi-language title

<html lang=en>
<title>Some title in English and a <i lang=fr>word in French</i></title>
Willdon answered 28/8, 2012 at 23:7 Comment(1)
un mot en Francais, peut-etre? (Sorry, no French keyboard, so no accents or cedillas.)Bono
M
21

See http://www.w3.org/TR/html401/struct/global.html#h-7.4.2:

Titles may contain character entities (for accented characters, special characters, etc.), but may not contain other markup (including comments).

(my emphasis)

Mark answered 28/8, 2012 at 23:10 Comment(1)
I've just found a legitimate need for markup inside <title>. Chrome uses the notranslate class value as an indication to not translate the text inside. If you wanted some part of the title not to be translated, you could do this <title>Page about <p class=notranslate>Brand Name</p></title>. Unfortunately it doesn't work. You can prevent the whole title from being translated or none of it, but not parts of it.Conscription
B
2

No, it may not

http://www.w3.org/Provider/Style/TITLE.html

Brail answered 28/8, 2012 at 23:11 Comment(0)
P
0

You can try to use whatever you want, but it will all be used as title string, without any additional parsing/processing from the browser (if that's what you expect). RFC says you have to resist from placing markup in title, though.

Plexus answered 28/8, 2012 at 23:10 Comment(4)
No, it will not work. No markup is recognized there, so e.g. the part <i lang=fr> will appear literally in contexts where the title element content is used, like tab labels.Brockway
@JukkaK.Korpela this is what I wrote. Read my comment again. You will see your markup on page title (usually on browser window title) unprocessed.Plexus
you wrote that ”it will work”. It won’t, because the purpose is clearly to mark some words as French, not to make <i lang=fr> appear. (And a reference to RFC is irrelevant; the last and only HTML version defined in a RFC was HTML 2.0.)Brockway
@JukkaK.Korpela but in previous sentence I said it will be used as regular string and not parsed. Edited my answer anyway.Plexus
H
0

TLDR: The <title> tag (1) must contain text (it must not be empty), (2) must only contain text (i.e. no other elements), and (3) must contain text that is not just white-space.


In HTML 5, the Content Model of the title element is:

Text that is not inter-element white space.

where inter-element white space is any Text node that is either empty or only contains sequences of space characters:

  • U+0020 SPACE
  • U+0009 CHARACTER TABULATION (tab)
  • U+000A LINE FEED (LF)
  • U+000C FORM FEED (FF)
  • U+000D CARRIAGE RETURN (CR)
Habitant answered 3/9, 2018 at 3:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.