[whatwg] Link element in body?

Ian Hickson ian at hixie.ch
Thu Aug 1 14:27:00 PDT 2013

On Wed, 20 Mar 2013, Benjamin Stürmer wrote:
> I've been thinking about this exact thing for the last few weeks, 
> because I have a use case in which it would be beneficial to use an 
> in-body <link> to include CSS files, especially if <link> could be 
> updated to support the "scoped" attribute with the same behavior as in 
> <style>.
> My use case is a CMS in which editable content is loaded into an editor 
> overlay via AJAX. This creates a bit of a nightmare due to the need to 
> keep strict separation between rules that apply to page content and 
> those that apply to the editor overlay, otherwise you end up with the 
> editor overlay getting styled by rules meant for the content. I've 
> solved the problem by introducing namespacing rules for CSS selectors, 
> but a much more elegant solution would be to include CSS via scoped 
> <link>s.
> I don't think that FOUC in and of itself is a strong argument against 
> allowing behavior like this. In my use case, FOUC wouldn't actually 
> occur, and in any case I suspect that authors to whom issues like FOUC 
> are important are aware of the significance of where they include their 
> CSS in their documents, and authors to whom issues like FOUC aren't 
> important aren't running their markup through validators in any case.

This is on my radar, but note that in the meantime you can use:

   <style>@import "my.css";</style>

At some point I plan to see how common it is for <style> elements to have 
@import rules; if it's common, then it would make sense to allow <link> in 
<body> for scoped style sheets as well. I hesitate to do it without a body 
of evidence showing it would be used a lot, because it's difficult to 
convey that <link rel="stylesheet scoped" href=""> would be allowed, while 
still having <link rel="stylesheet" href=""> and <link rel="next" href=""> 
non-conforming. I think authors would have more difficulty with the idea 
that certain rel="" values are ok in certain places, than they would with 
the idea that certain attributes are ok there and others aren't. (With 
microdata, it's easier, because we just don't allow rel="" at all.)

Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'

More information about the whatwg mailing list