How do I vertically align something inside a span tag?

mike picture mike · Apr 9, 2009 · Viewed 270.4k times · Source

How do I get the "x" to be vertically-aligned in the middle of the span?

.foo {
    height: 50px;
    border: solid black 1px;
    display: inline-block;
    vertical-align: middle;
}

<span class="foo">
   x
</span>

Answer

Sindre Sorhus picture Sindre Sorhus · Apr 9, 2009

Use line-height:50px; instead of height. That should do the trick ;)