0

I went to validate my HTML5 page today using the w3c validator and recieved an error message saying the style tag must have the scoped attribute if its not in the head section. So I added the scope attribute to my style tag and now I am getting this warning from the validator,

The scoped attribute on the style element is not supported by browsers yet. It would probably be better to wait for implementations.

So which is it? Use the scoped attribute, or dont? If I do not then I am getting an error from the validator, if I do than I am getting a warning saying not to use it.

5
  • Put your styles in the head. (If you can't, explain why, or the question isn't much of a question.) Jul 19, 2011 at 18:09
  • @Chris For this particular place there is a page specific style which I am not planning on moving at this momment.
    – Metropolis
    Jul 19, 2011 at 18:10
  • If you are absolutely hell-bent on using scoped styles, here is a jquery poly-fill( I believe there also may be a library independent one as well): thingsinjars.com/post/360/scoped-style
    – Moses
    Jul 19, 2011 at 18:30
  • @Moses I did not say I wanted to use the scoped attribute.....I asked why the validator is telling me to put it in, and then telling me to take it out, and what I should actually do with the scoped attribute.
    – Metropolis
    Jul 19, 2011 at 19:29
  • Keep this in mind: scoped isn't backwards compatible. So even when new versions of web browsers support it, it's going to cause problems. Jul 19, 2011 at 20:16

1 Answer 1

12

The validator will bitch at you if you have a style elem outside of the head. Scoping isnt supported and you should NOT do it for validation reasons, it has very explicit meanings in HTML5 and WebKit is soon landing support for it.

Browsers, on the other hand, don't give a shit about where your style elements are. So feel free to put them where you have to. (Assuming you have a good reason to put it outside of the head... which I'm curious about..)

Anyway, yet another example of how the validator does not reflect the reality of browsers. :)

2
  • It was actually old code that somebody put in a specific file because he/she did not want to put it in the template file since it was only needed on that page. It is not something I would advocate (or do), but I just wanted the page validated. It was just amazing to me that the validator tells you to put it in, and then tells you to take it out once you do.
    – Metropolis
    Jul 19, 2011 at 19:24
  • Not sure why everyone is jumping on my back about it as if I typically do that. I just had a question about the validation, not best style tag practice.
    – Metropolis
    Jul 19, 2011 at 19:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.