Jump to content

HTML/Body height - 100% or auto?


Nic727

Recommended Posts

Hi,

 

What is the best use of height for the HTML and body tag?

I currently use auto to don't have problem, but for my design, I need a background image to be height 100%. Should I use background height 100vh or 100% and have body/html height at 100%?

 

Thank you

Link to comment
Share on other sites

If you set height of body, html  to 100vh they will not extend beyond current viewport height of devices orientation, whatever the content and will show content beyond this background image when scrolled

If you set height of body, html to 100% they will extend to and beyond current viewport height only when content exceeds beyond that height of devices orientation and scroll along with extended background image.

Now depending what you want! You could use background-attachment: fixed; with height: 100vh to prevent background image scrolling up with content to show content extending beyond this html, body height background image.

Link to comment
Share on other sites

  • 9 months later...

If you're trying to apply background images to html and body that fill up the entire browser window, neither. Use this instead:

html{ height : 100%;} body{min-height : 100%;}

the reason why you have to specify height and min-height to html and body respectively is because neither element has any intrinsic height. Both are height: auto by default. It is the viewport that has 100% height, so height: 100% is taken from the viewport, then applied to body as a minimum to allow for scrolling of content.

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...