iOS 5.0 Safari not vertically centering placeholder in text box

Nirmal Patel picture Nirmal Patel · Dec 19, 2011 · Viewed 31.4k times · Source

I want to vertically center the text entered in input text boxes on the page.

Typical way to achieve this is to set the line-height and height equal. This works on pre iOS 5.0 Safari.

However; on iOS 5, Safari displays the typed text vertically centered... But the placeholder text and the cursor appear top aligned.

.txtBox {
    line-height: 3em;
    height: 3em;
}

<input type="text" class="txtBox" placeholder="Name"></input>

Anyone else facing this issue?

Answer

Marcel picture Marcel · Mar 26, 2014

For me there is only one solution that appears close to perfect in all browsers I tested (Chrome, FF, Safari (+iOS), IE10):

line-height: normal;

Solutions like line-height: 100% and line-height: 1; seem to be aligned towards the top of the input, especially in Chrome.

http://jsfiddle.net/5Vc3z/

Comparison:

http://jsfiddle.net/5Vc3z/1/