Centering image in HTML using CSS | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Centering image in HTML using CSS

Hello guys, I know that we can center and IMG tag by putting it within a phone tag then applying align attribute to it. e.g <p align="center" > This image is going to be centered <img src="url" width="240" />. </p> my question:. How can I achieve the same alignment above with CSS instead. <style> img{ ;} </style> ✊✊✊✊✊👍👍👍THANKS 👍👍👍✊✊✊ ENJOY THIS 🍓🍒🍓🍑🍏🍈🍇🍉🍊🍌🍍🌽🍆

15th Nov 2017, 11:19 AM
Keleos William
Keleos William - avatar
8 Answers
+ 10
img { display :block; margin : auto; }
15th Nov 2017, 11:24 AM
Md. Nafis Ul Haque Shifat
Md. Nafis Ul Haque Shifat - avatar
+ 10
vertical-align doesn't work for everybody
15th Nov 2017, 11:47 AM
NoxFly
NoxFly - avatar
+ 8
vertical-align:middle;
15th Nov 2017, 11:34 AM
qwerty
qwerty - avatar
+ 8
@Pegasus Using css not html
15th Nov 2017, 11:36 AM
qwerty
qwerty - avatar
+ 7
use float: ;
15th Nov 2017, 11:46 AM
NoxFly
NoxFly - avatar
+ 5
The text-align property specifies the horizontal alignment of text in an element. By default, text on your website is aligned to the left. However, at times you may require a different alignment. text-align property values are as follows: left, right, center, and justify. The vertical-align property sets an element's vertical alignment. Commonly used values are top, middle, and bottom. The example below shows how to vertically align the text between the table.
15th Nov 2017, 11:51 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 4
Nevermind I shall leave this instead. https://www.sololearn.com/Course/CSS/?ref=app
15th Nov 2017, 11:50 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 2
thanks all for the answers. I am finally able to align the img tag using text-align in CSS. this property is used to align almost anything else in HTML such as text, images, etc.
15th Nov 2017, 1:57 PM
Keleos William
Keleos William - avatar