When placing a vanilla textarea and an input side by side, the textarea appears higher as shown below,
textarea
input
Why is that so? How are their vertical alignments calculated?
Inspecting their CSS reveals both have vertical-align: baseline — where is the baseline against which they’re aligned?
vertical-align: baseline
2
Well first of all, there is no <input></input> with a closing tag. That does not exist because nothing can go "inside" of that tag. There is only a self-closing <input /> tag.
<input></input>
<input />
The default values (tested in Firefox) for:
<textarea>
vertical-align: text-bottom
<input>
Here’s how you can find out
<textarea></textarea> <input/>
A flexbox or a grid will help you get consistent positioning.
input, textarea { font-family: sans-serif; font-size: 20px; } .p1, .p2 { display: flex; gap: 2em; } .p1 { align-items: start; } .p2 { align-items: center; }
<p class="p1"> <textarea>Lorem ipsum dolor sit amet</textarea> <input value="Lorem ipsum"> </p> <p class="p2"> <textarea>Lorem ipsum dolor sit amet</textarea> <input value="Lorem ipsum"> </p>
Click here to cancel reply.
2
Answers
Well first of all, there is no
<input></input>
with a closing tag. That does not exist because nothing can go "inside" of that tag. There is only a self-closing<input />
tag.The default values (tested in Firefox) for:
<textarea>
isvertical-align: text-bottom
<input>
isvertical-align: baseline
Here’s how you can find out
A flexbox or a grid will help you get consistent positioning.