Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
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 '13 at 21:48
1  
added additional reasoning and sources –  World Engineer Nov 7 '13 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 '13 at 21:53
    
Fixed and shortened to better focus on the question at hand. –  World Engineer Nov 7 '13 at 21:55
    
thank you, this is a wonderful answer –  Malachi Nov 7 '13 at 21:59
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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