int(1)
Next Previous

CSS Make A Div Full Screen

There are multiple ways we can make a div take up the whole screen horizontally and vertically.

I have a simple div element with a class name box.

<div class="box">
</div>

Then, clear any default margin or padding from the html and body tags.

html, body {
  margin:0px;
}

height:100%

Before setting height property to 100% inside .box class, make sure to add it to both html and body tags as well, otherwise it won’t work.

html, body {
  margin:0px;
  height:100%;
}
.box {
  background:red;
  height:100%;
}

height:100vh

The .box class has only the 100vh which is 100% of the viewport height.

I do not have to add one for horizontal as div is a block-level element that will take the full width horizontally by default.



.box {
  background:red;
  height:100vh;
}

position:absolute

You can also use position absolute as well as setting all the viewport sides (top, right, bottom, left) to 0px will make the div takes the full screen.

.box {
  background:red;
  position:absolute;
  top:0px;
  right:0px;
  bottom:0px;
  left:0px;
}
Next Previous

Join Over 1000 🔥

Hey, Like What You're Reading?

JOIN to learn more about CSS


Valid 9th - 14th Jul 2020
85% OFF

Vue.js & Google Maps API: Build Location-Based Web Apps Like A Pro!

🔥 1086+ students enrolled!
4.85 ⭐️⭐️⭐️⭐️⭐️ (31+ ratings)

BEST SELLER