You can set the margin
property to auto
to horizontally center the element within its container.
The element will then take up the specified width, and the remaining space will be split equally between the left and right margins.
div {
width: 300px;
margin: auto;
border: 1px solid red;
}