How to center an image in CSS

When you have called up an image in HTML and you would like this image to be centered by means of CSS we would advise you to make use of margin: 0 auto; of text-align: center; . The best CSS property to be assigned differs from one situation to another. To make this clear in practice we will provide you with two clear CSS property examples. Please make sure you add the display: block; property to margin: 0 auto; to ensure a proper functionality:

<div>
<img src="image.jpg" width="100" height="100" />
</div>
div{
text-align: center;
}


Was this useful?