Ask coding questions

← Back to all posts
question
SaraMESHREKI (0)

How do I make my image be in the center on html?

Comments
hotnewtop
RYANTADIPARTHI (6006)

Solution

try doing text-align or margin-left

img {
    text-align: center;
}

or

img{
    margin-left: 100px; /* move it according to you */
}

any should work

FloCal35 (472)

Defire center in a css file

.center{
  float: center;
  text-align: center;
}

and then use it in a <img>

<img src="example.png" alt="example picture" class="center" style="width:500px;height:500px;">

Note: This will work for text and images

DavidSafro (19)

@FloCal35 .center is ok but you should do manual alignment in css to put where u want specifically