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:

New on Educative
Learn any Language for FREE all September 🎉
For the entire month of September, get unlimited access to our entire catalog of beginner coding resources.
🎁 G i v e a w a y
30 Days of Code
Complete Educative’s daily coding challenge every day in September, and win exciting Prizes.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved