Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy do textarea `cols` and input text `size` yield different element widths
    primarykey
    data
    text
    <p>I am trying to understand the behavior of the <code>cols</code> and <code>size</code> attributes for textarea and input text, respectfully. Although it should be something straight forward, I can't figure out <strong>why do they have different widths if the cols and size values are the same?</strong></p> <p>According to the documentation, both attributes should size the elements so that a given number of characters can fit inside:</p> <blockquote> <p>...<strong>size</strong> attribute <strong>specifies the visible width, in characters, of an input</strong> element. <a href="http://www.w3schools.com/tags/att_input_size.asp" rel="noreferrer">[source - w3schools]</a></p> <p>Note the <strong>cols</strong> and rows attributes (...) specify <strong>how many</strong> columns tall and <strong>rows wide</strong> to make the text area. The values are <strong>measured in characters</strong> .<a href="http://www.w3.org/community/webed/wiki/HTML_forms_-_the_basics" rel="noreferrer"> [source - w3]</a></p> </blockquote> <p>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.</p> <p>For example:</p> <pre><code>&lt;input type="text" size=40&gt; &lt;textarea cols="40"&gt;&lt;/textarea&gt; </code></pre> <p>produces:</p> <p><img src="https://i.stack.imgur.com/V1JR9.jpg" alt="textarea cols input text size"></p> <p>see here - <a href="http://jsfiddle.net/yjERR/" rel="noreferrer">http://jsfiddle.net/yjERR/</a></p> <p>I've tried this both in Chrome 29 and Firefox 24.</p> <p>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?</p> <p><strong>UPDATE</strong></p> <p>It seems the two elements have different font styles, however assigning the same font-family and font-size still produces different widths:</p> <p><img src="https://i.stack.imgur.com/F2zNm.jpg" alt="enter image description here"></p> <p><a href="http://jsfiddle.net/yjERR/10/" rel="noreferrer">udpated fiddle</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload