+ 2

How can I center a image?

Hello people of SoloLearn, I have been learning about HTML, when I was practicing the images and hyperlinks i cannot center the image, can someone help me with that? https://code.sololearn.com/Wyyid3ECVvje/?ref=app

3rd Jan 2018, 1:40 AM
Bismuto_42
Bismuto_42 - avatar
3 Réponses
+ 2
Here's an example code of how to center an image. Just add <p> around it and add style="text-align:center" to the tag. You can also set p's text-align attribute in the CSS tab. <p style="text-align:center"><img src="image link" /></p>
3rd Jan 2018, 1:51 AM
luciel
luciel - avatar
+ 1
but this is not a good idea, I think. You can center any image by centering div element by margin auto with some particular width.
3rd Jan 2018, 3:24 AM
Swarnab Das
Swarnab Das - avatar
+ 1
Both give you the same output, but div is a bit bigger whereas <p> wraps around the image without any trouble. Using paragraph is the best, simplest way, in my opinion, without having to go through extra steps to fix the size of the div.
3rd Jan 2018, 3:26 AM
luciel
luciel - avatar