Search code examples
htmlstylesheetw3c-validation

W3C HTML validator no longer accepts scoped styles


The following code used to validate OK on W3C a few months back:

<!DOCTYPE html>
<html>
    <head><title>Page Title</title></head>
    <body>
        <style type="text/css" scoped></style>
        test content 
    </body>
</html>

Currently the validator throws:

Element style not allowed as child of element body in this context.

Any ideas how to solve this?


Solution

  • Scoped styles have been removed from HTML.

    They do not appear in HTML 5 or HTML 5.1, and have been removed from Living HTML. (You can find a spec for them in a draft of HTML 5.1 but it didn't make it to the final version).

    Browser support is dying, Chrome removed support for them and only Firefox currently does support them.

    The validator reports them as an error because they are now an error. Stop using them.