Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial

Aishah Griffin
5,476 PointsCentering two images with html and css
How can I center two images. Here is my html: <!-- Body Images--> <div class="wrapper">
<img src="1sthome.jpg" alt="Headshot 1" id="homeimg">
<img src="2ndhome.jpg" alt="Headshot 2" id="homeimg2">
</div>
Here is the CSS:
homeimg {
width: 25%;
height:35%;
float: left;
padding: 10px;
text-align:center;
}
homeimg2 {
width:25%;
height: 37%;
float: left;
padding: 10px;
text-align: center;
}
3 Answers

Steven Parker
225,742 Points
This might be a good place to use flexbox.
Remove the float properties from the images and add this rule for the wrapper:
.wrapper {
display: flex;
justify-content: center;
}

Justin Thomas
11,097 PointsI believe you can also accomplish this by adding text-align center to the wrapper div containing the two images.
.wrapper { text-align: center; }

Steven Parker
225,742 PointsYou would still have to remove the "float
" properties from the images.

Aishah Griffin
5,476 PointsThank you. Both methods worked when removing the float properties from the images.