CSS – Vertical-Align Middle / Centered Text in a Div

Vertical Aligning text is actually quite easy. Set your container element to display:table, and your child element (doesn’t have to be a p, I used an a link element. I’m sure span and other things would work as well) to display:table-cell; and vertical-align:middle.



<div id="container"><p>Test</p></div>

The CSS:

display: table;

#container p{ //could be #container a, #container span, etc..
display: table-cell; 
vertical-align: middle;

Demo: blog.nerdstogeeks.com/2011/03/vertical-align-text-in-div-elements.html

About Steven Chu

Hi, I'm Steven! I'm an entrepreneur, photographer and art director in New York. Follow this blog for self expression, fun, and most importantly: looking comfortable, at ease, and amazing in your photos no matter who takes them! I dedicate this to my amazing friends who have let me inadvertently turn all of our hangouts and travel photos into a never ending photoshoot of fun. The proof is in the pudding-- our photos rock. My other projects: I'm the founder of InstaTechie.com, a face-to-face tech concierge service for NYC. Book a techie to walk you through something you want to learn! My work focuses on socially engaged art projects which use technology to create access to resources for communities. Visit Steven Chu Studio (stevenchustudio.com) for branding & design work or Steven Chu (stevenchu.com) for photography projects.

Leave a Reply