Search code examples
cssalignmentmargincenter

margin: 0 auto property values listed once vs twice


I'm brushing up on some basic CSS and I stumbled upon a tutorial that said to use:

margin: 0 auto 0 auto;

as opposed to...

margin: 0 auto;

by itself, to center something.

Can someone explain to me if there's any difference between putting 0 auto once, instead of twice? When I code, I don't notice a difference, so my guess is that using 0 auto, once is a short-hand that does the exact same thing.


Solution

  • No there is no diffrence between

    margin: 0 auto 0 auto;
    

    and

    margin: 0 auto;
    

    you can read more here

    When one value is specified, it applies the same margin to all four sides.

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

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

    When four values are specified, the margins apply to the top, right, bottom, and left in that order (clockwise).