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 to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved