In HTML5 the <script>
element is defined as being allowed in the following places:
Contexts in which this element can be used:
- Where metadata content is expected.
- Where phrasing content is expected.
- Where script-supporting elements are expected.
Most content elements allow for phrasing content
, and the <head>
element allows for metadata content
.
There are some elements that do not support the <script>
element as direct descendants , and it should be noted that this list is subject to change, so consult the spec, as this is probably not a comprehensive list:
Additionally, you shouldn't put a <script>
element in a <noscript>
element because it simply doesn't make any sense to do so, even though it would technically be supported by the specification.