How to centre an element in CSS

In the olden days of HTML development, in the late 90ies, we only had inline styles. Centring an element was done using the <center> property. That approach isn’t very elegant anymore in modern CSS šŸ™‚

Today we can use something like this:

#your-id .your-class {
    display: block;
    margin-left: auto;
    margin-right: auto;
}

It’s slightly more complicated than a single tag, but also opens up more options to tweak top and bottom margins at the same time.

You can leave a comment on my original post.