What is the difference between these two values? I've tested numerous examples and they just give the exact same result... Can someone please give me an example where flex-basis: auto;
does not give the same result as flex-basis: 0;

- 1,327
- 4
- 13
- 20
-
10@Michael_B: with respect, this question has not been asked before. The question you referred to is a different question. While one of the answers does mention these values for `flex-basis`, that is _not_ the focus of that question. When looking for exactly the same information, I am drawn to _this_ question, not the other. – Manngo Apr 08 '18 at 23:26
-
6@Michael_B yes, but you find the answer via the question, as I did. The comment _This question has been asked before and already has an answer_ is misleading. – Manngo Apr 08 '18 at 23:35
-
@Michael_B I don’t have the reputation points to vote for reopening the question, so I’ll have to say out of it :( – Manngo Apr 08 '18 at 23:41
-
2Good lord, Michael_B, you actually edited the title of the other question to make it look more like a duplicate of this one? I'm rolling that back, the title you gave it is not relevant to that question. – Daniel Beck Aug 01 '18 at 18:45
2 Answers
"0" and "auto" flex-basis will be different in most if not all situations: numeric values are interpreted as specific widths, so zero would be the same as specifying "width: 0"
-- and thus will collapse the element to its smallest possible width given the content, or to zero itself if its overflow is hidden or the element is directly sizable (an image for example.)
.f {display:flex}
.f div {border:1px solid}
.zero {flex-basis: 0}
.auto {flex-basis: auto}
<div class="f">
<div class="zero">This is flex-basis zero</div>
</div>
<div class="f">
<div class="auto">This is flex-basis auto</div>
</div>

- 20,653
- 5
- 38
- 53
-
1Important to note that "flex-basis:0" isn't the same as "width:0" when the flex item is an image. – Peter Out Apr 30 '21 at 14:28
-
-
2This image is pretty helpful: https://www.w3.org/TR/css-flexbox-1/images/rel-vs-abs-flex.svg – MattCochrane Jul 11 '22 at 23:43
I think what usually causes confusion with all this (or at least it did for me) is the fact that the final result is modified if other flex properties are added. Often, when looking for examples on flex-basis, these examples get mixed up with other flex properties that are affecting the final result. For example, if we add a flex-grow:1 to the great example given by Daniel Beck. In both cases the final result is the same, since you are telling the boxes: "grow as much as you can until you occupy the available space".
.f {
display: flex
}
.f div {
border: 1px solid
}
.zero {
flex-grow: 1;
flex-basis: 0;
}
.auto {
flex-grow: 1;
flex-basis: auto
}
<div class="f">
<div class="zero">This is flex-basis zero</div>
</div>
<div class="f">
<div class="auto">This is flex-basis auto</div>
</div>

- 501
- 6
- 6