Center an Element Horizontally Using the margin Property
Summary
- The
marginproperty is used to move an element horizontally. - To center a block element horizontally, set
marginto a value of auto.
Final Code
<style>
div {
background-color: blue;
height: 100px;
width: 100px;
margin: auto;
}
</style>
<div></div>