Search code examples
cssmargintext-justify

Centering with margin: 0 auto; vs. justify-content and flexbox


Doing some html horizontal center stuff, I just realized that I could use both things to center a box element into its parent, so my question is which of those 2 are better (in terms of performance, usability, etc).


Solution

  • If you use div or p it's better to use margin: 0px auto; for containers or main page, But if you need two or more children to be centered, it's better to set parent to text-align:center and the children to display: inline-block.