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