re: What does auto do in margin:0 auto? VIEW POST


Looking at the MDN article for CSS margin it says:

When two values are specified, the first margin applies to the top and bottom, the second to the left and right.

Citation: developer.mozilla.org/en-US/docs/W...

So margin: 0 auto is the same as the following 4 properties:

margin-top: 0;
margin-right: auto;
margin-bottom: 0;
margin-left: auto;

When margin-left and margin-right are both auto that will usually center-align a Block Level Element, like a <div>.

code of conduct - report abuse