Why does ‘overflow: auto’ clear floats? And why are clear floats needed?

The reason why the wrapper doesn’t stretch to contain its floats by default is because the floats are taken out of the normal flow of the wrapper, so the wrapper acts as if they were never there. If there is no other content in the wrapper, that means the wrapper won’t have any height.

Note that overflow: auto doesn’t clear floats — it just causes the element to contain its floats by way of establishing a new block formatting context for them so that they don’t intrude to other elements in the parent context.1 That is what forces the parent to stretch to contain them. You can only clear a float if you add a clearing element after the float. A parent element cannot clear its floating children.

The reason why establishing a new BFC causes an element to contain its floats is detailed here, and the reason why overflow: auto would even cause a BFC to be established is detailed here.


1 OK, maybe “just” wasn’t exactly the best adverb to use.

Leave a Comment