Explore Courses Blog Tutorials Interview Questions
0 votes
in Web Technology by (20.3k points)

Is the property text-align: center; a good way to center an image using CSS?

img {

    text-align: center;


1 Answer

0 votes
by (40.7k points)

The code you have mentioned will not work as the text-align property applies to block containers, not inline elements, and img is an inline element. 

For more information, you can refer to this document: the W3C spec 

You can use the code given below instead of that: {

    display: block;

    margin: 0 auto;


<div style="border: 1px solid black;">

<img class="center" src ="?v=c78bd457575a">


Related questions

Browse Categories