How to align an image in the center of div
Use the following steps to center align an image in the middle of a div container:
- Create a div container.
- Insert the image tag in order to tell the source of the image.
- In the CSS, set the left and right margins to
auto. - 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 ©2026 Educative, Inc. All rights reserved