<?xml version="1.0" encoding="utf-8"?>

CSS margin auto value

CSS margin auto value Bad Practice
CSS margin auto value Best Practice

Unlike padding, margin can have the auto value. You can either set this value for both left and right margin or the shorthand margin property only. The browser centers the element, like text or image, within its container horizontally. The element will take up the width you specify, while the remaining space will be split evenly between the left and right margin.

Setting auto values for vertical margin (top and bottom) doesn't make much sense. The element will be pulled to the edge with a margin value equal to 0.

Improve your UX & Product skills with interactive courses that actually work