How can I make Flexbox children 100% height of their parent?

flexbox fill remaining height
flexbox height fit content
flexbox height: 100
css fill parent height
div fill remaining height of parent
flexbox make child height of parent
how to make child divs always fit inside parent div
css fill remaining height

I'm trying to fill the vertical space of a flex item inside a Flexbox.

.container {
  height: 200px;
  width: 500px;
  display: flex;
  flex-direction: row;
.flex-1 {
  width: 100px;
  background-color: blue;
.flex-2 {
  position: relative;
  flex: 1;
  background-color: red;
.flex-2-child {
  height: 100%;
  width: 100%;
  background-color: green;
<div class="container">
  <div class="flex-1"></div>
  <div class="flex-2">
    <div class="flex-2-child"></div>
Use align-items: stretch

Similar to David Storey's answer, my workaround is:

.flex-2 {
    display: flex;
    align-items: stretch;

Alternatively to align-items, you can use align-self just on the .flex-2-child item you want stretched.

How to make flexbox children 100% height of their parent using CSS , Their parent boxes height might also be determined by their height combined, but it Duration: 13:15 Posted: Jan 31, 2014 Making a flex-box child 100% height of their parent can be done in two ways. It is little tricky because, certainly it will display an error. For example, the child may flow out of the parent boundary or it may not get upto 100% height that you will see in your browser output. Example 1: This example makes a child flex-box of height 100% using CSS.

Boxes That Fill Height (Or More) (and Don't Squish), Support the development of JSFiddle and get extra features ✌ . Become a supporter. HTML  * { padding: 0; margin: 0; box-sizing: border-box; } body { margin: 50px; } .navbar { display: flex; align-items: center; justify-content: center; color: darkgreen

If I understand correctly, you want flex-2-child to fill the height and width of its parent, so that the red area is fully covered by the green?

If so, you just need to set flex-2 to use flexbox:

.flex-2 {
    display: flex;  

Then tell flex-2-child to become flexible:

.flex-2-child {    
    flex: 1;


The reason is that flex-2-child is not a flexbox item, but its parent is.

Height 100% in Flexbox Item - JSFiddle, For example, floats do not intrude into the flex container, and the flex container's .parent {. display: flex;. flex-flow: row nowrap;. height: 250px;. } .child { are evenly distributed in the alignment container, with a full-size space on either end. 3 Answers3. Active Oldest Votes. 114. You should set height of html, body, .wrapper to 100% (in order to inherit full height) and then just set a flex value greater than 1 to .row3 and not on the others.

I suppose that Chrome's behavior is more consistent with the CSS spec (though it's less intuitive). According to Flexbox spec, the default stretch value of align-self property changes only the used value of the element's "cross size property" (height, in this case). And, as I understand the CSS2.1 spec, the percentage heights are calculated from the specified value of the parent's height, not its used value. The specified value of the parent's height isn't affected by any flex properties and is still auto.

Setting explicit height: 100% makes it formally possible to calculate the percentage height of the child, just like setting height: 100% to html makes it possible to calculate the percentage height of body in CSS2.1.

Flex Cheatsheet, In addition, this is a known issue in chrome and safari but appears to make the flex-item element as flexbox, and remove height 100% from .element they shouldn't respect height: 100% unless the parent flex item has a 0  Flexbox - Children expand to fill height. Ask Question Asked 3 years, 11 months ago. How can I make Flexbox children 100% height of their parent? 674.

I found the solution by myself, suppose you have the CSS below:

.parent {
  align-items: center;
  display: flex;
  justify-content: center;

.child {
  height: 100%; <- didn't work

In this case, setting the height 100% will not work, so what I do is setting the margin-bottom rule to auto, like:

.child {
  margin-bottom: auto;

and the child will be aligned to the topmost of the parent, you can also use the align-self rule anyway if you prefer.

.child {
  align-self: flex-start;

100% height doesn't work within a flex item in a flex-item child, The flex-basis CSS property sets the initial main size of a flex item. flex-basis: auto; /* Intrinsic sizing keywords */ flex-basis: fill; flex-basis: max-content; flex-​basis: a <percentage> of the parent flex container's main size property, or the keyword auto . Get the latest and greatest from MDN delivered straight to your inbox. Teaching Kids To Play By Themselves : Life Kit American parents often feel like event planners for their kids. There's a pressure to make sure kids are entertained and content every minute of the day.

flex-basis, See demo below where the flexbox spans the viewport height: body { margin: 0; } *{ box-sizing: border-box; } .row { display: flex; flex-direction: column; height:  Ideally, I want it to be a div, that's a flex container, which I can then put 4 flex items into and have each of them take up a quarter of the space available each, but because the div with the yellow border cannot seem to see the height of the parent container (The red sidebar, which is a flex item itself) then it only ever takes up the height

How to make flexbox children 100% height of their parent, For the parent: display: flex;. You should add some other prefixes as well. For more information refer to this doc:  In other words, for percentage height to work on an in-flow child, the parent must have a set height. In your code, the top-level container has a defined height: .container { height: 20em; } The third-level container has a defined height: .item-inner { height: 100%; }

How to force child div to be 100% of parent div's height without , Quickly create grids, masonry, stacks and more layouts with these 10 CSS flexbox templates. a few boxes to stretch and fill the full width of their parent element. flex on the container, and a flex-grow value above 0 on the children: .container { display: flex; } .item { height: 100px; width: 100px; /* A fixed  It’s hard to sum up all the awesome that is flexbox in a little ol’ blog post. Although we gave it a shot here.Here, let’s just try and focus on one thing that flexbox solves very nicely: the ability to have an arbitrary set of boxes fill up all the available height of a parent box.

  • what is the problem with using height:100%; for .flex-2 ?
  • It defies the purpose of the flex item which is to fill the content by itself and it's giving me the weirdest bug in chrome where the height goes back to zero whenever I resize the window
  • Actually, the latest version of Firefox is the only one working properly
  • Currently, there are significant differences in behavior among browsers when it comes to rendering percentage heights in flexbox:
  • Yep, Chrome has some issues, especially with nested flexboxes. For example I've got a nested flex box with children that have height:100% but they are rendering with natural height instead. And the weird thing is if I change their height to auto, then they render as height:100% like I was trying to do. It is definitely not intuitive if that's how it should work.
  • stretch: this should be the chosen answer.
  • Definitely this is far the best answer for the question. Works perfectly.
  • Yes, this is indeed the best answer for this question.
  • don't forget to also remove height: 100% from children component that you want to same height as parent
  • Please add removing height: 100% to the answer - I nearly gave up and only saw this at the last moment before reverting to absolute - which comes with all sorts of problems.