How to right align in CSS

Monir Khan
1 min readSep 21, 2020

--

An alternative to float: right

Flexbox right align

There are many stackoverflow questions about aligning the last element to the right of a container, as we used to do before with float: right.

There are many solutions out there as flexbox is really flexible. but my recommendations are the ones below. I have listed two solutions depending on if you want to set it from the container element or the from the element itself.

Option one — justify-content:space-between on the containerElement

Option two — mergin-left: auto on the HTMLElement itself

Added a code pen with both examples.

--

--

Monir Khan
Monir Khan

Written by Monir Khan

System developer, Swedish board of agriculture

No responses yet