How to Give an Element the Height of the Window

Published December 26, 2016 by CSS Newbies.

Setting the width of an element to the full window height is done pretty commonly, but it’s a lot more rare for an element to be given the full height of a window. The strategy behind stretching an element to the full height of the window is essentially the same as stretching an element to the full width. In both of these instances, the element will only be able to be as wide or as long as it’s container element, so you have to first make sure that all of the parent elements take up the entire width or height of the window before you can apply the height: 100% to your targeted element.

So for example, let’s say you have a div called .container that you want to have take up the entire height of the window. First, you’ll need to make the html, body, and any other parent elements of .container have a height of 100%:

html, body {
  height: 100%;
}

From there it should be easy to stretch the height of all your remaining parent divs until you get to .container:

container{
   height: 100%;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>