act-rules.github.io icon indicating copy to clipboard operation
act-rules.github.io copied to clipboard

Multiple <title> tags in a web page

Open giacomo-petri opened this issue 11 months ago • 4 comments

In HTML page has non-empty title we say:

While this is invalid in HTML, the HTML 5.2 specification describes what should happen in case of multiple titles, and titles outside the head element.

However, upon delving, I couldn't locate any explicit mention of this in the HTML 5.2 specifications.

Could someone direct me to the source where it details the expected behavior in cases of multiple

tags? <p>Thanks</p>

giacomo-petri avatar Mar 22 '24 10:03 giacomo-petri

Indeed, can't find it either (not even in parsing rules). It should be replaced by something like "browsers/AT behave consistently" (may need some extra testing that all the passed examples indeed pass in most common combinations...)

Jym77 avatar Mar 23 '24 12:03 Jym77

I'll address this with a PR, first making sure that browsers expose consistently the same title.

giacomo-petri avatar Mar 24 '24 18:03 giacomo-petri

Outcomes of my test:

Scenario Chrome Safari Firefox
2 titles, both in <head> The computed title is the 1st in list The computed title is the 1st in list The computed title is the 1st in list
2 titles, both in <body> The computed title is the 1st in list The computed title is the 1st in list The computed title is the 1st in list
2 titles, both after the <body> (parsing issue but it happens) The computed title is the 1st in list The computed title is the 1st in list The computed title is the 1st in list
2 titles, 1 in <head>, 1 in <body> The computed title is the 1st in list (the one in head) The computed title is the 1st in list (the one in head) The computed title is the 1st in list (the one in head)
2 titles, 1 in <head>, 1 after the <body> (parsing issue but it happens) The computed title is the 1st in list (the one in head) The computed title is the 1st in list (the one in head) The computed title is the 1st in list (the one in head)
2 titles, 1 in <body>, 1 after the <body> (parsing issue but it happens) The computed title is the 1st in list (the one in body) The computed title is the 1st in list (the one in body) The computed title is the 1st in list (the one in body)
2 titles, 1 in <head>, 1 inside a shadowroot (open and closed) The computed title is the 1st in list (the one in head), shadowroot title is ignored The computed title is the 1st in list (the one in head), shadowroot title is ignored The computed title is the 1st in list (the one in head), shadowroot title is ignored

Proceeding with the PR.

giacomo-petri avatar Apr 15 '24 08:04 giacomo-petri

It is defined here in the HTML Standard:

The title element of a document is the first title element in the document (in tree order), if there is one, or null otherwise.

https://html.spec.whatwg.org/multipage/dom.html#the-title-element-2

However, upon delving, I couldn't locate any explicit mention of this in the HTML 5.2 specifications.

Do you really mean the HTML 5.2 specification? The HTML 5.2 spec was obsoleted in 2019 and replaced by the WHATWG HTML Standard: https://www.w3.org/html/

dd8 avatar Jun 13 '24 12:06 dd8

Completed

giacomo-petri avatar Sep 02 '24 10:09 giacomo-petri