Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

css
html

How to align an image in the center of div

Fahad Farid
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:

RELATED TAGS

css
html

CONTRIBUTOR

Fahad Farid
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring