How to Center an Image in CSS

For beginners it’s a big question how you will center an image using CSS.

If you’ve been coding HTML for a ling time, you may probably know the HTML tag to center an image.

Long time ago, people center different objects using <center> tag.

But due to some modernization in HTML and CSS. The best way to center an image using CSS is the code below.

img{
margin: 0 auto;
display: block;
clear: both;
}

Keep in mind that you need to declare clear: both to clear any floats that are present before the image that you want to align to center.

*Some links may contain affiliate links. I may get small commission from your purchases to fund this website and to avoid annoying ads.