How to center an element horizontally using margins
January 9th 2024Summary
One of the easiest ways of centering elements horizontally in CSS it to use margins. It is common to see this on approach used with wrapping container elements. This article shows you how.
The Code
CSS
.centered {
display: block;
margin-left: auto;
margin-right: auto;
}