Is it bad to set a class on HTML element?

Hi All

I need one page in my site to have a different background color to the rest, and the only way I seem to be able to do this is by applying a class to the HTML element and styling that. Using a class on the Body element doesn’t work, as on longer pages the body doesn’t wrap around the content, so the color only goes as far as the fold.

I’m pretty sure it’s not in the spec to set a class on the HTML element… Is this bad practice?

I guess I could also add styles directly to that page, overriding my external stylesheet, but that also feels pretty dirty.

Are there other ways to approach this?

Thanks, Frank

Thanks for the reply. I’m afraid my CSS is pretty huge and all on my local development site - will try to get something online to illustrate…

Well using styles inline is not a good practice. You tell us that you couldn’t use a class because the body doesn’t wrap. I guess this is because your content is floated. Try clear the float or use an overflow:hidden property on your body. Maybe if you could provide us some code you’ll get a better answer

I think I solved it - there was a body {height:100%} lurking in my code. The reason I couldn’t just style the HTML is that I wanted to use just one external stylesheet, so it would effect every page. I’ve now just added that style to that page, and that works fine.

Thanks for your help!

I had the same reaction.

… and if the BODY tag isn’t wrapping around the content, there’s something REALLY screwed up in the markup.

Why do you need a class on the html element. There is only one html element allowed in a page so you could just apply the style to html elements rather than to a class.