Masatoshi Nishiguchi
Software Engineer

Float an element to the right using CSS Flexbox

css flexbox

Every now and again, there is a situation where I want to make an HTML elemnt float to the right. I could use CSS float property; however its resulting behavior is sometimes counterintuitive and it requires something called “Clearfix hack”.

As an alternative, I found it much more intuitive to use CSS Flexbox and a spacer element. All I need to do is:

then that spacer will stretch out and push the subsequent elements to the right.

That’s it.