Ask coding questions

← Back to all posts
Center image
KamronGorney (7)

Can you tell me how to center an image i've been trying for hours and i still can't find out how to can someone please help me with my troubles

Answered by PYer (4015) [earned 5 cycles]
View Answer
PYer (4015)

set the margins to auto and the display to block then add it as a class to the image element.

.center {
  display: block;
  margin-left: auto;
  margin-right: auto;
  width: 50%;

then do <img src="image.jpg" alt="image" class="center">
Please mark this comment as the answer