align an image in the center of a div code example

Example 1: how to center an image element inside a block in css

img { display:block;
      margin-left: auto;
      margin-right:auto;
      }

Example 2: 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>

Tags:

Misc Example