How to align an image in the center of div

svg viewer

Use the following steps to center align an image in the middle of a div container:

  1. Create a div container.
  2. Insert the image tag in order to tell the source of the image.
  3. In the CSS, set the left and right margins to auto.
  4. Change the display to block.

The image should now be center aligned.

Below is a working code example you can use to better understand the concept:

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved