Css height in percent not working

I have the following simple code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

  <title>Live Feed</title>

  <meta http-equiv="content-type" content="text/html; charset=UTF-8" />

    body {
      margin: 0px;
      padding: 0px;

  <div style="background-color: #eeaabb; width: 250px; height: 100%; border-right: solid 1px #e1e1e1;">
    I should be tall


But the div doesn’t get displayed with height being 100%. Why?


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You need to set a 100% height on all your parent elements, in this case your body and html. This fiddle shows it working.

html, body { height: 100%; width: 100%; margin: 0; }
div { height: 100%; width: 100%; background: #F52887; }

Method 2

Make it 100% of the viewport height:

div {
  height: 100vh;

Works in all modern browsers and IE>=9, see here for more info.

Method 3

height: 100% works if you give a fixed size to the parent element.

Method 4

You can achieve that by using positioning.


position: absolute;

to get the 100% height.

Method 5

You need to set 100% height on the parent element.

Method 6

Add height:100% to body


Method 7

the root parent have to be in pixels if you want to work freely with percents,

<body style="margin: 0px; width: 1886px; height: 939px;">
<div id="containerA" class="containerA" style="height:65%;width:100%;">
    <div id="containerAinnerDiv" style="position: relative; background-color: aqua;width:70%;height: 80%;left:15%;top:10%;">
       <div style="height: 100%;width: 50%;float: left;"></div>
       <div style="height: 100%;width: 28%;float:left">
            <img src="img/justimage.png" style="max-width:100%;max-height:100%;">
       <div style="height: 100%;width: 22%;float: left;"></div>

Method 8

This is what you need in the CSS:

html, body {
    height: 100%; 
    width: 100%; 
    margin: 0; 

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x