how to align images to center in html | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

how to align images to center in html

align="center" doesn't work

27th Jun 2018, 10:20 AM
kumar keshav
10 Answers
+ 2
key to understanding is that img is an inline element. best way imo is to wrap img with a div, a block element and a meaningful id attribute. then use css to center content in the div. dont use html align attribute. alignment is a styling issue. use css for styling. html to describe content. html... <div id="centerimg"> <img src="img.jpg" alt="alttext"> </div> css... #centerimg { text-align: center; }
1st Jul 2018, 12:45 PM
Lisa F
Lisa F - avatar
0
thanks fr answering can't be done using html?? just started cssšŸ˜€šŸ˜€
27th Jun 2018, 10:22 AM
kumar keshav
0
then use align=middle
27th Jun 2018, 10:45 AM
Abhishek Rawat
Abhishek Rawat - avatar
0
align="middle" works??
27th Jun 2018, 11:00 AM
kumar keshav
0
yup... check na
27th Jun 2018, 11:06 AM
Abhishek Rawat
Abhishek Rawat - avatar
27th Jun 2018, 11:39 AM
kumar keshav
0
doesn't work
27th Jun 2018, 11:40 AM
kumar keshav
0
you know what.. first check your source of img... an img source must end with img file extensions.. like jpg, png, jpeg.. please
27th Jun 2018, 11:43 AM
Abhishek Rawat
Abhishek Rawat - avatar
0
image is loading bro, no problem there. i have reduced the size to see the alignment. it is not compulsory that the src must end with jpg, png,
27th Jun 2018, 12:28 PM
kumar keshav
0
Hi kumar keshav, Try replacing align="middle" with style="margin: 50%;" This should provide centering both vertically and horizontally with respect to the block. I hope this helps! :)
27th Jun 2018, 9:16 PM
Janningā­
Janningā­ - avatar