CSS Height: auto vs 100%

difference between css height : 100% vs height : auto

by manoj_antony32

HTML

<!-- height:100% implies the element is going to have the 100% height of its parent container.

height:auto means, the element will have flexible height i.e. its height will depend upon the height of children elements of it

Consider below example:

height:100% -->
<div style="height:50px">
    <div id="innerDiv" style="height:100%;border:1px solid grey;">
    hello
    </div>
</div>
<!-- #innerDiv is going to have height:50px

height:auto -->

<div style="height:50px">
    <div id="innerDiv" style="height:auto">
          <div id="evenInner" style="height:10px;border:1px solid grey;">
          hello1
          </div>
    </div>
</div>
<!-- now the #innerDiv is going to have height:10px -->