Languages

CSS - make div element 100% height of the browser window

0 points
Asked by:
Jan-Alfaro
681

How can I expand div element vertically depending on the user's browser window height?

I've tried height: 100% and min-height: 100% unsuccessfully.

1 answer
0 points
Answered by:
Admin Dirask Community
4380

Quick solution:

If you want to set the height of an element to the 100% of the web browser window, you should also set the height of <body> and <html> to 100%.

Note:

Go to the documentation to read more about relative length units.

Practical example

Explanation - height: 100vh vs height: 100%

  • height: 100vh means 100% of the viewport height,
  • height: 100% means 100% of the parent's element height.

That's why you need to use height: 100vh on the element or add height: 100% on html and body, as they don't have a size by default.

 

References

  1. CSS values and units - Learn web development | MDN
0 commentsAdd comment
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join