2
votes

I have a style element within the body of a HTML document like this:

<body>
<style scoped >
…

But when validating with W3C I get this error:

Element style not allowed as child of element body in this context.
(Suppressing further errors from this subtree.)

I thought that if you added the scoped attribute you could add the style element in the body. I need to add it in the body because we don't have access to the head.

Is there something wrong?

1

1 Answers

1
votes

The scoped attribute was removed before HTML5 became a W3C Recommendation, so you cannot use it in HTML5 documents.

Therefore, you can use the style element only where "metadata content is expected" (i.e., in the head element).

The scoped attribute is still part of the Editor's Draft of HTML 5.1 Nightly (stable link to current Working Draft).