style and script tags in HTML body… why not?

后端 未结 7 2019
野的像风
野的像风 2020-11-29 06:57

[This is related to this question, but not since it\'s not about email.]

In many cases -- especially when working with a CMS or someone else\'s fram

相关标签:
7条回答
  • 2020-11-29 07:55

    The contexts in which the <script> and <style> tags can be used depends on the doctype you're using. For instance, I'll assume you're using the HTML5 doctype:

    <!DOCTYPE html>
    

    The script tag has three contexts under the HTML5 doctype:

    1. Where metadata content is expected.
    2. Where phrasing content is expected.
    3. Where script-supporting elements are expected.

    The style tag has a slightly more complicated context-structure under the HTML5 doctype:

    1. If the scoped attribute is absent: where metadata content is expected.
    2. If the scoped attribute is absent: in a noscript element that is a child of a head element.
    3. If the scoped attribute is present: where flow content is expected, but before any other flow content other than inter-element whitespace and style elements, and not as the child of an element whose content model is transparent.

    Essentially, this states that you can place the style tag and the script tag in the body, since the body is where we place flow content, and phrasing content.

    As always, consult the spec for the doctype you're using.

    0 讨论(0)
提交回复
热议问题