0

Is it valid to use html

html {
  border: solid 10px #000;
  background-color: #EE3E4E;
} 

instead of body

body {
  border: solid 10px #000; 
  background-color: #EE3E4E;
} 

in CSS?

ProEvilz
  • 5,310
  • 9
  • 44
  • 74
Gray
  • 11
  • 4

2 Answers2

0

Absolutely you can, its just should you is the main question, but again thats all convention. Most prefer to set defaults in the body tag, so another stylist touching your site may expect defaults there. Of course just an inspection tool will show them where the defaults are. So Yep, but convention usually dictates body would be your "default" style pane

Rando
  • 473
  • 2
  • 12
  • I'm doing the responsive version of my website and for some reason the border of the body gets smaller instead of staying around the body's edges... When I changed to html it got slightly better, but still with some flaws. – Gray Jan 02 '19 at 04:52
  • its possible that another style is overriding, if you go through an element inspector you might see something sitting over the top, or even the values changing (f12 on chrome/ie, then the elements tab, you can generally hover your mouse over each element for it to highlight on the page) – Rando Jan 02 '19 at 04:56
  • @Gray if that is actually your question, you should put that in the question! Now do you have a padding on `html` as well? Or, by "smaller", do you mean the border around the body is as high as its content rather than the size of the viewport? – Mr Lister Jan 02 '19 at 07:17
0

Yes, you can. It will just change everything in between. Almost all of the tags can be used in CSS