0

How to center an image in HTML ?

recently I am just working on my blog and I have got a problem in img tag I want to center image in HTML I know it's possible if I add css but I need an alternative so I can only use HTML

8th Aug 2021, 4:55 AM
46 72 65 79
46 72 65 79 - avatar
4 Answers
+ 4
Even though you can use center attribute to centerize an image, it's not the advisable method. And many styling attribute in html including center attribute are going to deprecated soon, means any time your html styling attributes are not going to work on new browsers soon. To style a html page, it's better to use css.
8th Aug 2021, 5:02 AM
CalviŐ˛
CalviŐ˛ - avatar
+ 3
Frey yes, it works. But it will not work in new browsers soon. Please read this https://developer.mozilla.org/en-US/docs/Web/HTML/Element/center "Deprecated This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time." So why not use css, which is working always.
8th Aug 2021, 5:13 AM
CalviŐ˛
CalviŐ˛ - avatar
0
CalviŐ˛ thanks well <center> </center> alway works out
8th Aug 2021, 5:03 AM
46 72 65 79
46 72 65 79 - avatar
0
You can do that, by making the image element display as a block, The default display of an image element or the image element is display:inline; You can try img{ display: inline-block; margin-left: auto; margin-right: auto; }
8th Aug 2021, 5:12 AM
Jonathan P. Jundarino
Jonathan P. Jundarino - avatar