place image in center of its parent code example

Example 1: html how to center an image to a parent element

<!DOCTYPE html>
<html>
  <head>
    <title>Center an Image using text align center</title>
    <style>
      .img-container {
        text-align: center;
        display: block;
      }
    </style>
  </head>
  <body>
    <span class="img-container"> <!-- Inline parent element -->
      <img src="user.png" alt="">
    </span>
  </body>
</html>

Example 2: html how to center an image to a parent element

.element {
    object-fit: fill || contain || cover || none || scale-down;
}

Tags:

Html Example