Sujan Khadka Posted on Dec 5, 2019 What does auto do in margin:0 auto? #css #beginners #javascript #php Top comments (2) Subscribe Personal Trusted User Create template Templates let you quickly answer FAQs or store snippets for re-use. Submit Preview Dismiss Collapse Expand Richard JP Le Guen Richard JP Le Guen Richard JP Le Guen Follow Location Montreal, Quebec Education BEng, Concordia University (Montreal) Work Software Developer at Broadsign Joined Dec 5, 2019 • Dec 5 '19 • Edited on Dec 5 • Edited Dropdown menu Copy link Hide 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>. Collapse Expand Sujan Khadka Sujan Khadka Sujan Khadka Follow Software developer👨🏻💻| Location Queensland, Australia Education Master of Information Systems (MISP) Work Dev Joined Nov 15, 2019 • Dec 5 '19 Dropdown menu Copy link Hide Thanks! Code of Conduct • Report abuse Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink. Hide child comments as well Confirm For further actions, you may consider blocking this person and/or reporting abuse
Top comments (2)
Looking at the MDN article for CSS
margin
it says:Citation: developer.mozilla.org/en-US/docs/W...
So
margin: 0 auto
is the same as the following 4 properties:When
margin-left
andmargin-right
are bothauto
that will usually center-align a Block Level Element, like a<div>
.Thanks!