Startec
Startec

Reputation: 13206

Is it necessary (or advisable) to add CSS styling to the HTML element?

When looking at other people's code (or many CSS resets), I see the html element addressed with basic styling (like height: 100%) and sometimes I see it ignored completely. In my experimentation there is no difference, but I am not sure if I am missing something.

In this post they give the example of

html,body{
   min-height: 101%;
}

to keep scrollbars visible (but no other definitive answer). Other than a hack like this, is there any specific reason to style the html element?

Upvotes: 1

Views: 133

Answers (3)

Dave 5000
Dave 5000

Reputation: 346

As I understand it, it is the html element that displays scrollbars. So if you don't want to display scrollbars at all for some reason you would need to hide overflow on that element.

More information about the html element here

Upvotes: 0

T J
T J

Reputation: 43156

Well the major reason i can think of is that, for specifying height in % the elements parent needs to have a height set explicitly.

Assume you've a container <div> which you need to be of 100% height and responsive. simply applying height:100% won't work unless you specify a height for it's parent <body>.

Hence we'll apply height:100% for the <body> - Now, this won't work since <body>'s parent doesn't have a height set explicitly - which is our <html> element.

Hence we apply

html{
 height:100%;
}

...!

This is not required if your design is not responsive , i.e if you're setting fixed dimensions in pixels

Upvotes: 1

Ken Wheeler
Ken Wheeler

Reputation: 1958

This is used for making height:100% relative to the viewport height.

Upvotes: 0

Related Questions