Using CSS to Vertically Align Images with Text
If you have ever tried to vertically align an image within a line of text these instructions should help. I added a border around each of these images so it's easier to see how the text aligns with the images and to separate it from the rest of the content on this page.
How to set up Text Aligned to Bottom of Image:
First you need to set up the CSS file with this class:
Then add that class to your image tag:
This should align the bottom of the image with the bottom of the text as shown in the image above. However, notice that the text is not actually leven with the bottom of the image. If you prefer that instead, then see the baseline alignment below.
If your setting this up for mobile devices and the image is wider than 280 pixels (smallest mobile device) then leave out the width and height, otherwise you can leave it in.
Other image postions
Text aligned to middle:
Text aligned to top:
Text to baseline:
You might notice that the bottom and baseline of the image is slightly different. The baseline setting letters like a lower case "g" to hang lower than the bottom of the image, so a baseline looks like the text is exactly at the bottom of the image.
Here are all 4 alignment items listed together. Just copy and paste this into your CSS file.
Return to HTML TIPS
© 2007 Updated 1-12-19
Lori's Web Design
All Rights Reserved