I am trying to understand the behavior of the cols
and size
attributes for textarea and input text, respectfully. Although it should be something straight forward, I can't figure out why do they have different widths if the cols and size values are the same?
According to the documentation, both attributes should size the elements so that a given number of characters can fit inside:
...size attribute specifies the visible width, in characters, of an input element. [source - w3schools]
Note the cols and rows attributes (...) specify how many columns tall and rows wide to make the text area. The values are measured in characters . [source - w3]
However if I try to assign the same value to both elements, they end up being with different widths. The input field is a bit too small to accommodate the given number of chars and the the textarea - too wide. Most importantly, both have different width.
For example:
<input type="text" size=40>
<textarea cols="40"></textarea>
produces:
see here - http://jsfiddle.net/yjERR/
I've tried this both in Chrome 29 and Firefox 24.
I understand that width depends on font styles, but shouldn't both elements still have the same width? Are internal element margins or something else causing this difference?
UPDATE
It seems the two elements have different font styles, however assigning the same font-family and font-size still produces different widths:
input
andtextarea
have different fonts. – Perreault