Aaron Kuzemchak


CSS Vertical Align: A Quick Cheat Sheet

Posted on June 23, 2009 at 8:39pm / Filed under: CSS / 4 comments

First of all: no, this is not a tutorial telling you how to vertically center text or other elements with CSS. If that's what you're looking for, I can't help you (at least, not in this entry). If you're still interested, read on.

I found myself today doing something that I feel happens to often in Web design: wasting precious time going through the different values for the CSS vertical-align property. I would try middle, then baseline, then text-bottom, then back to middle again… and I'm sure that I'm not the only one who does this. All I wanted to do was vertically center a button and a text link, and the whole while I kept thinking to myself "if only I could see all at one time what each of the values would look like, that would make this go so much faster." So, here it is. It's not much, but it should do the job.

Edit: I should have made it clear that the vertical-align is targeting the button only, so where the button appears in relation to the text is how the vertical-align option will display.

Vertical align settings

Reader comments

brilliant! thanks for whipping this up!

one small edit: sub and super appear swapped.

Posted by Lance Roggendorff on June 24, 2009 at 7:02am

thanks lance. however, sub and super are appearing correctly. they determine if the button will align with sub text or super text. i suppose i should have mentioned that the button was the focus of the vertical-align. will make an edit now.

Posted by Aaron Kuzemchak on June 24, 2009 at 8:35am

Should probably also mention that there are some subtle differences between IE6(PC) and most other browsers on some of these (‘middle’ comes immediately to mind). Of course, this is only an issue if you bother with hacking for IE6…

Posted by Kevin on June 29, 2009 at 9:35am

Thanks Kevin. See here for my thoughts on IE6, hahaha!

http://aaronkuzemchak.com/blog/entry/no-love-for-ie6-here/

Posted by Aaron Kuzemchak on June 29, 2009 at 9:38am

Commenting is not available in this channel entry.