Skip to content
This repository has been archived by the owner on Jul 30, 2019. It is now read-only.

make <style> in <body> conforming #544

Closed
prlbr opened this issue Jul 28, 2016 · 21 comments
Closed

make <style> in <body> conforming #544

prlbr opened this issue Jul 28, 2016 · 21 comments

Comments

@prlbr
Copy link
Contributor

prlbr commented Jul 28, 2016

Please consider making <style> in <body> conforming.

  • <style> in <body> apparently works in all major browsers
  • it is useful for and indeed used by authors working with CMSs who don’t have access to the <head> at all or at least not easily on a page by page basis

See the corresponding issue at WHATWG by @workguy66.

@chaals
Copy link
Collaborator

chaals commented Jul 31, 2016

See also #516, which is asking to stop it conforming… I think that in the current draft it is, but in any event, I think that we can cover this question within #516 - if you agree, please close this one.

@prlbr
Copy link
Contributor Author

prlbr commented Aug 2, 2016

As I understand it, #516 asks for an editorial change that would make a non-normative part of the spec be consistent with a normative part of the spec. It’s about consistency in the spec, not about which behaviour is desirable. So I think that’s neither the same nor the converse of this issue here.

But I see that the discussion in #516 actually goes in the direction of discussing which behaviour is desirable, so this question could indeed be covered there. But will it be? Or is someone going to say: “That’s not what this issue is about, please open a new one for your request”? Will people whom this issue here concerns find that other issue, if the other issue’s title and initial post don’t reflect what’s discussed there? Those are questions that make me feel uneasy about closing this one here. Not sure what to do.

@prlbr
Copy link
Contributor Author

prlbr commented Aug 2, 2016

To be clear, <style> in <body> shall work like <style> in <head>. The content of <style> shall not be written as text on the page. Millions of sites use it like this. For example, https://www.google.com/ does.

@adanilo
Copy link

adanilo commented Aug 29, 2016

Agreed, this seems to be in widespread use so the reality of the web... Would you like to propose some text, or even a PR?

@chaals
Copy link
Collaborator

chaals commented Oct 3, 2016

I'm closing this as a duplicate of #516 - where the "trending conclusion" is to make style conforming in the body...

Thanks for raising it in this form though - I think it helped the discussion.

@chaals chaals closed this as completed Oct 3, 2016
@chaals chaals reopened this Dec 1, 2016
@chaals chaals added this to the HTML 5.2 WD 3 milestone Dec 1, 2016
@AndySky21
Copy link

AndySky21 commented Dec 1, 2016 via email

@TakayoshiKochi
Copy link
Member

As @travisleithead commented in #516 (comment), if <style> is not allowed in <body>, <style> in shadow DOM won't work as expected.

@chaals
Copy link
Collaborator

chaals commented Dec 1, 2016

@AndySky21 given that browsers have already worked this way for a couple of decades, I suspect authors are not likely to start getting confused now.

@workguy66
Copy link

workguy66 commented Dec 1, 2016

@AndySky21 I disagree, to me it's pretty obvious that the style flickering is due to poor CMS coding, not that the style tag in body behaves the way that it is expected to behave.

@LJWatson LJWatson modified the milestones: HTML 5.2 WD 4, HTML 5.2 WD 3 Jan 10, 2017
@adanilo
Copy link

adanilo commented Jan 13, 2017

Appears we have agreement to document it as conforming as per existing browser behaviour. @prlbr would you like to propose some text?

@chaals chaals modified the milestones: HTML 5.2 WD 5, HTML 5.2 WD 4 Jan 13, 2017
@prlbr
Copy link
Contributor Author

prlbr commented Jan 14, 2017

I guess not much text is needed, but the definition box of the element needs to be changed to allow <style> to be also where flow-content is expected and hence the explanation of flow content and maybe a few other references need to be updated?

I don’t feel ready to make these changes and would be happy if someone more knowledgable with the spec could take care of this. Thank you for the offer though, @adanilo!

@stevefaulkner
Copy link
Contributor

Also being discussed in whatwg world whatwg/html#1605

@LJWatson LJWatson modified the milestones: HTML 5.2 WD 5, HTML 5.2 WD 6 Feb 26, 2017
@workguy66
Copy link

workguy66 commented Feb 27, 2017 via email

@chaals
Copy link
Collaborator

chaals commented Feb 27, 2017

@workguy66 That's exactly what we think about. If the spec is ambiguous here, it isn't clear exactly what they would do. But it turns out that a browser that didn't allow style in the body wouldn't work on the Web.

We have an option to make it non-conforming but require browsers to handle it, and describe how to do that - this is what we do for a bunch of things, including appcache.

But there are use cases for doing it, and no clear reason I can see to prohibit it, although it's often not the best idea.

@AndySky21
Copy link

Instead of being marked "non conforming but supported", which sounds quite strange, why not marking it "conforming with warning"? I.e. when validated (and in spec) it should be stated that putting style in body can be done, but as last resort only and underlining the problem that can be caused by that (essentially FOUC if tons of content are loaded before style itself is parsed and applied).
It's up to the authors then to balance pros and cons (e.g. if style is parsed before the weighty stuff, or if style rules apply to dynamically inserted elements, it's quite safe)

After all, if UAs have learnt how to cope with that, now it's just a matter of usability trade-off. Not to mention all the CMSs, hubs and platforms which physically do not allow authors to insert whatever they want inside the document's head.

@ExplodingCabbage
Copy link

@chaals and @workguy66, you say that a fully-compliant browser wouldn't support <style> in the body at all, but according to @domenic in whatwg/html#1605 (comment):

just to be very clear: this entire issue is not about changing browser behavior. The spec already requires, and browsers already implement, processing for <style> in body. It works, albeit with the negative effects I discussed above.

(emphasis mine)

I'm not sure precisely what @domenic's reasoning is for how the spec requires this, and don't know whether there are relevant differences between the W3C and WhatWG specs in this regard, but it seems that he disagrees with you.

@workguy66
Copy link

workguy66 commented Mar 1, 2017 via email

adanilo pushed a commit to adanilo/html that referenced this issue Mar 29, 2017
pointing out that use in the body can trigger unwanted side
effects. See Issue w3c#544.
@chaals
Copy link
Collaborator

chaals commented Mar 29, 2017

style should also be listed as flow content, no? in dom.include at #flow-content

chaals pushed a commit that referenced this issue Mar 30, 2017
pointing out that use in the body can trigger unwanted side
effects. See Issue #544.
@adanilo adanilo closed this as completed Mar 30, 2017
chaals pushed a commit that referenced this issue Mar 30, 2017
* Added note that removes the restriction of <style> in <head> but
pointing out that use in the body can trigger unwanted side
effects. See Issue #544.

* Added style to the set of flow content elements.
arronei pushed a commit to arronei/html that referenced this issue Apr 17, 2017
…#843)

pointing out that use in the body can trigger unwanted side
effects. See Issue w3c#544.
arronei pushed a commit to arronei/html that referenced this issue Apr 17, 2017
* Added note that removes the restriction of <style> in <head> but
pointing out that use in the body can trigger unwanted side
effects. See Issue w3c#544.

* Added style to the set of flow content elements.
@prlbr
Copy link
Contributor Author

prlbr commented May 3, 2017

The element box for the style element says for “Contexts in which this element can be used”:

  • Where metadata content is expected.
  • In a noscript element that is a child of a head element.

I think this should be changed to where flow content is expected.

chaals pushed a commit that referenced this issue May 3, 2017
see #544 - this is cleaning up the change already made.
@chaals
Copy link
Collaborator

chaals commented May 3, 2017

@prlbr agreed. I made a PR - feel free to review it...

@prlbr
Copy link
Contributor Author

prlbr commented May 3, 2017

Looks good, thank you!

travisleithead pushed a commit that referenced this issue May 19, 2017
see #544 - this is cleaning up the change already made.
chaals pushed a commit that referenced this issue Jul 5, 2017
* Added note that removes the restriction of <style> in <head> but
pointing out that use in the body can trigger unwanted side
effects. See Issue #544.

* Added style to the set of flow content elements.

* Partial commit for adding referrerpolicy.

* Hard set for non-binary on the .include files, fixes merge pain.

* Added attribute to stop git treating text files as binary.

* Added referrer policy attribute for link reference resource fetch

* Ported the commits from issue #560. Next, find other commits
that this needs for completeness (attribute defs, IDL, etc.)

* Addded definition section for referrer policy

* Added a few more referrerpolicy references.

* Bulk of referrerpolicy changes, check in for backup in reality.

* Fixed up a bunch of link errors.

* Fixed a few more linking errors, fixed typo.

* Changes as per review, plus some markup cleanup.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants