You can style the <body>
tag if you wish, but using a class for body is not useful. Use an ID for greater specificity and control.
Classes are for declarations that will be used in more than one place on a document and/or on more than one page. ID’s are unique identifiers.
The <body>
tag represent the content of the document, the <body>
tag is not invisible. Since the body tag can be styled, I don’t know why you were told it wasn’t directly visible, the body is the entire document itself.
Here’s a snippet of CSS I used in a project to illustrate some of what styling you can do with the <body>
tag;
body {
background-color: rgb(238, 238, 238);
font-family: 'Source Sans Pro', sans-serif;
}
I want the background to be that color with equates to the hex #eee
and I want those fonts to be used for the entire document unless I specifically place a value on a property (such as an <h2>
tag).
Instead of W3Schools, which states in the footer on every page;
W3Schools is optimized for learning, testing, and training. Examples might be simplified to improve reading and basic understanding. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content.
I suggest to people that they go to the MDN Docs. So in this case, read through Learn to style HTML using CSS - Learn web development | MDN
I’d also point people to http://www.w3fools.com/
Today, W3Schools has largely resolved these issues and addressed the majority of the undersigned developers’ concerns. For many beginners, W3Schools has structured tutorials and playgrounds that offer a decent learning experience. Do keep in mind: a more complete education will certainly include MDN and other reputable resources.
If you want to really have an educated and thorough understanding of the cascade, the spec, and CSS as a whole, I suggest MDN over most anything.
I’d rather get my information from a lot of people in the industry that know what they are talking about rather than a nameless bunch running a site that no one has ever known who is behind it.
Folks can say they have helped a lot of beginners, and that is fine and good, but over the years, and I have seen it since the inception of the site, they don’t practice what they preach and if I’m learning and when I am teaching others, I have plenty of other reliable resources that I find more reliable.
Lastly, I leave it up for debate elsewhere. w3schools: The Ugly, the Bad, and the Good
Good luck!