is it good Coding Practice to add style to the <html> tag of a web document?

why should you not style the <html> tag of a web document?

I ask this because of this answer on a StackOverflow question.
Personally I don't think this is good coding practice.

is there a WC3 standard that says this is good/bad?

1 Answer 1


There's the matter of cross-browser inconsistencies between the <html> tag and the <div> tag, with the <div> having more consistent behavior. The w3c recommends that you style the <body> tag rather than the <html> tag. Much of this again has to do with modern browser behavior:

Many web developers do not understand the difference between applying style to the body element versus the html element. Most of the time these authors will apply style only to the body element; when that's not sufficient, they'll spam all sorts of styles on both html and body until the page happens to look correct.

The confusion is understandable. In the beginning, both were treated similarly, with (now-deprecated) attributes like bgcolor being applied to the body tag, affecting the whole page.

This article attempts to enlighten you, Web Developer, to fully grok how these two elements are used in modern web browsers.

  • maybe I should rephrase the question, I completely agree with what you are saying, but what I want to know is " should you style the <html> tag? "
    – Malachi
    Nov 7, 2013 at 21:48
  • 1
    added additional reasoning and sources
    – user28988
    Nov 7, 2013 at 21:51
  • 2
    I think he means "Should you use html as a selector (in your CSS file)?", not "Should you put style rules in your html file".
    – iCanLearn
    Nov 7, 2013 at 21:53
  • Fixed and shortened to better focus on the question at hand.
    – user28988
    Nov 7, 2013 at 21:55
  • I am going to give this some time to attract other answers.
    – Malachi
    Nov 7, 2013 at 22:02

Your Answer

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

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