<p>I'm currently working on an internal sales application for the company I work for, and I've got a form that allows the user to change the delivery address.</p>

<p>Now I think it would look much nicer, if the textarea I'm using for the main address details would just take up the area of the text in it, and automatically resize if the text was changed.</p>

<p>Here's a screenshot of it currently.</p>

<p><img src="https://i.stack.imgur.com/XK48E.png" alt="ISO Address"></p>

<p>Any ideas?</p>

<hr>

<p>@Chris</p>

<p>A good point, but there are reasons I want it to resize. I want the area it takes up to be the area of the information contained in it. As you can see in the screen shot, if I have a fixed textarea, it takes up a fair wack of vertical space.</p>

<p>I can reduce the font, but I need address to be large and readable. Now I can reduce the size of the text area, but then I have problems with people who have an address line that takes 3 or 4 (one takes 5) lines. Needing to have the user use a scrollbar is a major no-no.</p>

<p>I guess I should be a bit more specific. I'm after vertical resizing, and the width doesn't matter as much. The only problem that happens with that, is the ISO number (the large "1") gets pushed under the address when the window width is too small (as you can see on the screenshot).</p>

<p>It's not about having a gimick; it's about having a text field the user can edit that won't take up unnecessary space, but will show all the text in it.</p>

<p>Though if someone comes up with another way to approach the problem I'm open to that too.</p>

<hr>

<p>I've modified the code a little because it was acting a little odd. I changed it to activate on keyup, because it wouldn't take into consideration the character that was just typed.</p>

<pre><code>resizeIt = function() {
  var str = $('iso_address').value;
  var cols = $('iso_address').cols;
  var linecount = 0;

  $A(str.split("\n")).each(function(l) {
    linecount += 1 + Math.floor(l.length / cols); // Take into account long lines
  })

  $('iso_address').rows = linecount;
};
</code></pre>

[{'answer_id': 7523, 'author': 'Orion Edwards', 'author_id': 234, 'author_profile': 'https://Stackoverflow.com/users/234', 'pm_score': 7, 'selected': True, 'text': '<p>Facebook does it, when you write on people\'s walls, but only resizes vertically.</p>\n\n<p>Horizontal resize strikes me as being a mess, due to word-wrap, long lines, and so on, but vertical resize seems to be pretty safe and nice.</p>\n\n<p>None of the Facebook-using-newbies I know have ever mentioned anything about it or been confused. I\'d use this as anecdotal evidence to say \'go ahead, implement it\'.</p>\n\n<p>Some JavaScript code to do it, using <a href="http://en.wikipedia.org/wiki/Prototype_JavaScript_Framework" rel="noreferrer">Prototype</a> (because that\'s what I\'m familiar with):</p>\n\n<pre><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"\n  "http://www.w3.org/TR/html4/loose.dtd"&gt;\n&lt;html&gt;\n    &lt;head&gt;\n        &lt;script src="http://www.google.com/jsapi"&gt;&lt;/script&gt;\n        &lt;script language="javascript"&gt;\n            google.load(\'prototype\', \'1.6.0.2\');\n        &lt;/script&gt;\n    &lt;/head&gt;\n\n    &lt;body&gt;\n        &lt;textarea id="text-area" rows="1" cols="50"&gt;&lt;/textarea&gt;\n\n        &lt;script type="text/javascript" language="javascript"&gt;\n            resizeIt = function() {\n              var str = $(\'text-area\').value;\n              var cols = $(\'text-area\').cols;\n\n              var linecount = 0;\n              $A(str.split("\\n")).each( function(l) {\n                  linecount += Math.ceil( l.length / cols ); // Take into account long lines\n              })\n              $(\'text-area\').rows = linecount + 1;\n            };\n\n            // You could attach to keyUp, etc. if keydown doesn\'t work\n            Event.observe(\'text-area\', \'keydown\', resizeIt );\n\n            resizeIt(); //Initial on load\n        &lt;/script&gt;\n    &lt;/body&gt;\n&lt;/html&gt;\n</code></pre>\n\n<p>PS: Obviously this JavaScript code is very naive and not well tested, and you probably don\'t want to use it on textboxes with novels in them, but you get the general idea.</p>\n'}, {'answer_id': 7875, 'author': 'Shog9', 'author_id': 811, 'author_profile': 'https://Stackoverflow.com/users/811', 'pm_score': 5, 'selected': False, 'text': '<p>Here\'s another technique for autosizing a textarea.</p>\n\n<ul>\n<li>Uses pixel height instead of line height: more accurate handling of line wrap if a proportional font is used.</li>\n<li>Accepts either ID or element as input</li>\n<li>Accepts an optional maximum height parameter - useful if you\'d rather not let the text area grow beyond a certain size (keep it all on-screen, avoid breaking layout, etc.)</li>\n<li>Tested on Firefox 3 and <a href="http://en.wikipedia.org/wiki/Internet_Explorer_6" rel="noreferrer">Internet&nbsp;Explorer&nbsp;6</a></li>\n</ul>\n\n<p><strong>Code:</strong>\n(plain vanilla JavaScript)</p>\n\n<pre><code>function FitToContent(id, maxHeight)\n{\n   var text = id &amp;&amp; id.style ? id : document.getElementById(id);\n   if (!text)\n      return;\n\n   /* Accounts for rows being deleted, pixel value may need adjusting */\n   if (text.clientHeight == text.scrollHeight) {\n      text.style.height = "30px";\n   }\n\n   var adjustedHeight = text.clientHeight;\n   if (!maxHeight || maxHeight &gt; adjustedHeight)\n   {\n      adjustedHeight = Math.max(text.scrollHeight, adjustedHeight);\n      if (maxHeight)\n         adjustedHeight = Math.min(maxHeight, adjustedHeight);\n      if (adjustedHeight &gt; text.clientHeight)\n         text.style.height = adjustedHeight + "px";\n   }\n}\n</code></pre>\n\n<p><strong>Demo:</strong>\n(uses jQuery, targets on the textarea I\'m typing into right now - if you have <a href="http://en.wikipedia.org/wiki/Firebug_%28software%29" rel="noreferrer">Firebug</a> installed, paste both samples into the console and test on this page)</p>\n\n<pre><code>$("#post-text").keyup(function()\n{\n   FitToContent(this, document.documentElement.clientHeight)\n});\n</code></pre>\n'}, {'answer_id': 68428, 'author': 'Mike', 'author_id': 841, 'author_profile': 'https://Stackoverflow.com/users/841', 'pm_score': 2, 'selected': False, 'text': '<p>Just revisiting this, I\'ve made it a little bit tidier (though someone who is full bottle on <a href="http://en.wikipedia.org/wiki/Prototype_JavaScript_Framework" rel="nofollow noreferrer">Prototype</a>/JavaScript could suggest improvements?).</p>\n\n<pre><code>var TextAreaResize = Class.create();\nTextAreaResize.prototype = {\n  initialize: function(element, options) {\n    element = $(element);\n    this.element = element;\n\n    this.options = Object.extend(\n      {},\n      options || {});\n\n    Event.observe(this.element, \'keyup\',\n      this.onKeyUp.bindAsEventListener(this));\n    this.onKeyUp();\n  },\n\n  onKeyUp: function() {\n    // We need this variable because "this" changes in the scope of the\n    // function below.\n    var cols = this.element.cols;\n\n    var linecount = 0;\n    $A(this.element.value.split("\\n")).each(function(l) {\n      // We take long lines into account via the cols divide.\n      linecount += 1 + Math.floor(l.length / cols);\n    })\n\n    this.element.rows = linecount;\n  }\n}\n</code></pre>\n\n<p>Just it call with:</p>\n\n<pre><code>new TextAreaResize(\'textarea_id_name_here\');\n</code></pre>\n'}, {'answer_id': 946565, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>I needed this function for myself, but none of the ones from here worked as I needed them.</p>\n\n<p>So I used Orion\'s code and changed it.</p>\n\n<p>I added in a minimum height, so that on the destruct it does not get too small.</p>\n\n<pre><code>function resizeIt( id, maxHeight, minHeight ) {\n    var text = id &amp;&amp; id.style ? id : document.getElementById(id);\n    var str = text.value;\n    var cols = text.cols;\n    var linecount = 0;\n    var arStr = str.split( "\\n" );\n    $(arStr).each(function(s) {\n        linecount = linecount + 1 + Math.floor(arStr[s].length / cols); // take into account long lines\n    });\n    linecount++;\n    linecount = Math.max(minHeight, linecount);\n    linecount = Math.min(maxHeight, linecount);\n    text.rows = linecount;\n};\n</code></pre>\n'}, {'answer_id': 948445, 'author': 'Jeremy Kauffman', 'author_id': 82124, 'author_profile': 'https://Stackoverflow.com/users/82124', 'pm_score': 3, 'selected': False, 'text': "<p>Here's a <strong>Prototype</strong> version of resizing a text area that is not dependent on the number of columns in the textarea. This is a superior technique because it allows you to control the text area via CSS as well as have variable width textarea. Additionally, this version displays the number of characters remaining. While not requested, it's a pretty useful feature and is easily removed if unwanted.</p>\n\n<pre><code>//inspired by: http://github.com/jaz303/jquery-grab-bag/blob/63d7e445b09698272b2923cb081878fd145b5e3d/javascripts/jquery.autogrow-textarea.js\nif (window.Widget == undefined) window.Widget = {}; \n\nWidget.Textarea = Class.create({\n  initialize: function(textarea, options)\n  {\n    this.textarea = $(textarea);\n    this.options = $H({\n      'min_height' : 30,\n      'max_length' : 400\n    }).update(options);\n\n    this.textarea.observe('keyup', this.refresh.bind(this));\n\n    this._shadow = new Element('div').setStyle({\n      lineHeight : this.textarea.getStyle('lineHeight'),\n      fontSize : this.textarea.getStyle('fontSize'),\n      fontFamily : this.textarea.getStyle('fontFamily'),\n      position : 'absolute',\n      top: '-10000px',\n      left: '-10000px',\n      width: this.textarea.getWidth() + 'px'\n    });\n    this.textarea.insert({ after: this._shadow });\n\n    this._remainingCharacters = new Element('p').addClassName('remainingCharacters');\n    this.textarea.insert({after: this._remainingCharacters});  \n    this.refresh();  \n  },\n\n  refresh: function()\n  { \n    this._shadow.update($F(this.textarea).replace(/\\n/g, '&lt;br/&gt;'));\n    this.textarea.setStyle({\n      height: Math.max(parseInt(this._shadow.getHeight()) + parseInt(this.textarea.getStyle('lineHeight').replace('px', '')), this.options.get('min_height')) + 'px'\n    });\n\n    var remaining = this.options.get('max_length') - $F(this.textarea).length;\n    this._remainingCharacters.update(Math.abs(remaining)  + ' characters ' + (remaining &gt; 0 ? 'remaining' : 'over the limit'));\n  }\n});\n</code></pre>\n\n<p>Create the widget by calling <code>new Widget.Textarea('element_id')</code>. The default options can be overridden by passing them as an object, e.g. <code>new Widget.Textarea('element_id', { max_length: 600, min_height: 50})</code>. If you want to create it for all textareas on the page, do something like:</p>\n\n<pre><code>Event.observe(window, 'load', function() {\n  $$('textarea').each(function(textarea) {\n    new Widget.Textarea(textarea);\n  });   \n});\n</code></pre>\n"}, {'answer_id': 1820197, 'author': 'lorem monkey', 'author_id': 221381, 'author_profile': 'https://Stackoverflow.com/users/221381', 'pm_score': 1, 'selected': False, 'text': "<p>Here is an extension to the Prototype widget that Jeremy posted on June 4th:</p>\n\n<p>It stops the user from entering more characters if you're using limits in textareas. It checks if there are characters left. If the user copies text into the textarea, the text is cut off at the max. length:</p>\n\n<pre><code>/**\n * Prototype Widget: Textarea\n * Automatically resizes a textarea and displays the number of remaining chars\n * \n * From: http://stackoverflow.com/questions/7477/autosizing-textarea\n * Inspired by: http://github.com/jaz303/jquery-grab-bag/blob/63d7e445b09698272b2923cb081878fd145b5e3d/javascripts/jquery.autogrow-textarea.js\n */\nif (window.Widget == undefined) window.Widget = {}; \n\nWidget.Textarea = Class.create({\n  initialize: function(textarea, options){\n    this.textarea = $(textarea);\n    this.options = $H({\n      'min_height' : 30,\n      'max_length' : 400\n    }).update(options);\n\n    this.textarea.observe('keyup', this.refresh.bind(this));\n\n    this._shadow = new Element('div').setStyle({\n      lineHeight : this.textarea.getStyle('lineHeight'),\n      fontSize : this.textarea.getStyle('fontSize'),\n      fontFamily : this.textarea.getStyle('fontFamily'),\n      position : 'absolute',\n      top: '-10000px',\n      left: '-10000px',\n      width: this.textarea.getWidth() + 'px'\n    });\n    this.textarea.insert({ after: this._shadow });\n\n    this._remainingCharacters = new Element('p').addClassName('remainingCharacters');\n    this.textarea.insert({after: this._remainingCharacters});  \n    this.refresh();  \n  },\n\n  refresh: function(){ \n    this._shadow.update($F(this.textarea).replace(/\\n/g, '&lt;br/&gt;'));\n    this.textarea.setStyle({\n      height: Math.max(parseInt(this._shadow.getHeight()) + parseInt(this.textarea.getStyle('lineHeight').replace('px', '')), this.options.get('min_height')) + 'px'\n    });\n\n    // Keep the text/character count inside the limits:\n    if($F(this.textarea).length &gt; this.options.get('max_length')){\n      text = $F(this.textarea).substring(0, this.options.get('max_length'));\n        this.textarea.value = text;\n        return false;\n    }\n\n    var remaining = this.options.get('max_length') - $F(this.textarea).length;\n    this._remainingCharacters.update(Math.abs(remaining)  + ' characters remaining'));\n  }\n});\n</code></pre>\n"}, {'answer_id': 2032642, 'author': 'Jan Miksovsky', 'author_id': 76472, 'author_profile': 'https://Stackoverflow.com/users/76472', 'pm_score': 6, 'selected': False, 'text': '<p>One refinement to some of these answers is to let CSS do more of the work.</p>\n\n<p>The basic route seems to be:</p>\n\n<ol>\n<li>Create a container element to hold the <code>textarea</code> and a hidden <code>div</code></li>\n<li>Using Javascript, keep the <code>textarea</code>’s contents synced with the <code>div</code>’s</li>\n<li>Let the browser do the work of calculating the height of that div</li>\n<li>Because the browser handles rendering / sizing the hidden <code>div</code>, we avoid\nexplicitly setting the <code>textarea</code>’s height.</li>\n</ol>\n\n<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">\r\n<div class="snippet-code">\r\n<pre class="snippet-code-js lang-js prettyprint-override"><code>document.addEventListener(\'DOMContentLoaded\', () =&gt; {\r\n    textArea.addEventListener(\'change\', autosize, false)\r\n    textArea.addEventListener(\'keydown\', autosize, false)\r\n    textArea.addEventListener(\'keyup\', autosize, false)\r\n    autosize()\r\n}, false)\r\n\r\nfunction autosize() {\r\n    // Copy textarea contents to div browser will calculate correct height\r\n    // of copy, which will make overall container taller, which will make\r\n    // textarea taller.\r\n    textCopy.innerHTML = textArea.value.replace(/\\n/g, \'&lt;br/&gt;\')\r\n}</code></pre>\r\n<pre class="snippet-code-css lang-css prettyprint-override"><code>html, body, textarea {\r\n    font-family: sans-serif;\r\n    font-size: 14px;\r\n}\r\n\r\n.textarea-container {\r\n    position: relative;\r\n}\r\n\r\n.textarea-container &gt; div, .textarea-container &gt; textarea {\r\n    word-wrap: break-word; /* make sure the div and the textarea wrap words in the same way */\r\n    box-sizing: border-box;\r\n    padding: 2px;\r\n    width: 100%;\r\n}\r\n\r\n.textarea-container &gt; textarea {\r\n    overflow: hidden;\r\n    position: absolute;\r\n    height: 100%;\r\n}\r\n\r\n.textarea-container &gt; div {\r\n    padding-bottom: 1.5em; /* A bit more than one additional line of text. */ \r\n    visibility: hidden;\r\n}</code></pre>\r\n<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="textarea-container"&gt;\r\n    &lt;textarea id="textArea"&gt;&lt;/textarea&gt;\r\n    &lt;div id="textCopy"&gt;&lt;/div&gt;\r\n&lt;/div&gt;</code></pre>\r\n</div>\r\n</div>\r\n</p>\n'}, {'answer_id': 2046661, 'author': 'Larry', 'author_id': 248584, 'author_profile': 'https://Stackoverflow.com/users/248584', 'pm_score': 1, 'selected': False, 'text': '<p>Internet Explorer, Safari, Chrome and <a href="http://en.wikipedia.org/wiki/Opera_%28web_browser%29" rel="nofollow noreferrer">Opera</a> users need to remember to explicidly set the line-height value in CSS. I do a stylesheet that sets the initial properites for all text boxes as follows.</p>\n\n<pre><code>&lt;style&gt;\n    TEXTAREA { line-height: 14px; font-size: 12px; font-family: arial }\n&lt;/style&gt;\n</code></pre>\n'}, {'answer_id': 3094600, 'author': 'Alex', 'author_id': 326938, 'author_profile': 'https://Stackoverflow.com/users/326938', 'pm_score': 1, 'selected': False, 'text': '<p>Here is a function I just wrote in jQuery to do it - you can port it to <a href="http://en.wikipedia.org/wiki/Prototype_JavaScript_Framework" rel="nofollow noreferrer">Prototype</a>, but they don\'t support the "liveness" of jQuery so elements added by Ajax requests will not respond.</p>\n\n<p>This version not only expands, but it also contracts when delete or backspace is pressed.</p>\n\n<p>This version relies on jQuery 1.4.2.</p>\n\n<p>Enjoy ;)</p>\n\n<p><a href="http://pastebin.com/SUKeBtnx" rel="nofollow noreferrer">http://pastebin.com/SUKeBtnx</a></p>\n\n<p>Usage:</p>\n\n<pre><code>$("#sometextarea").textareacontrol();\n</code></pre>\n\n<p>or (any jQuery selector for example)</p>\n\n<pre><code>$("textarea").textareacontrol();\n</code></pre>\n\n<p>It was tested on <a href="http://en.wikipedia.org/wiki/Internet_Explorer_7" rel="nofollow noreferrer">Internet&nbsp;Explorer&nbsp;7</a>/<a href="http://en.wikipedia.org/wiki/Internet_Explorer_8" rel="nofollow noreferrer">Internet&nbsp;Explorer&nbsp;8</a>, Firefox 3.5, and Chrome. All works fine.</p>\n'}, {'answer_id': 3157451, 'author': 'Gyan', 'author_id': 381047, 'author_profile': 'https://Stackoverflow.com/users/381047', 'pm_score': 3, 'selected': False, 'text': '<p>Check the below link:\n<a href="http://james.padolsey.com/javascript/jquery-plugin-autoresize/" rel="nofollow noreferrer">http://james.padolsey.com/javascript/jquery-plugin-autoresize/</a></p>\n\n<pre><code>$(document).ready(function () {\n    $(\'.ExpandableTextCSS\').autoResize({\n        // On resize:\n        onResize: function () {\n            $(this).css({ opacity: 0.8 });\n        },\n        // After resize:\n        animateCallback: function () {\n            $(this).css({ opacity: 1 });\n        },\n        // Quite slow animation:\n        animateDuration: 300,\n        // More extra space:\n        extraSpace:20,\n        //Textarea height limit\n        limit:10\n    });\n});\n</code></pre>\n'}, {'answer_id': 3409937, 'author': 'memical', 'author_id': 322622, 'author_profile': 'https://Stackoverflow.com/users/322622', 'pm_score': 3, 'selected': False, 'text': '<p>Here is a solution with <code>JQuery</code>:</p>\n\n<pre><code>$(document).ready(function() {\n    var $abc = $("#abc");\n    $abc.css("height", $abc.attr("scrollHeight"));\n})\n</code></pre>\n\n<p><code>abc</code> is a <code>teaxtarea</code>.</p>\n'}, {'answer_id': 4596541, 'author': 'WNRosenberg', 'author_id': 332472, 'author_profile': 'https://Stackoverflow.com/users/332472', 'pm_score': 1, 'selected': False, 'text': '<p><a href="https://stackoverflow.com/questions/7477/autosizing-textarea#3409937">@memical</a> had an awesome solution for setting the height of the textarea on pageload with jQuery, but for my application I wanted to be able to increase the height of the textarea as the user added more content.  I built off memical\'s solution with the following:</p>\n\n<pre><code>$(document).ready(function() {\n    var $textarea = $("p.body textarea");\n    $textarea.css("height", ($textarea.attr("scrollHeight") + 20));\n    $textarea.keyup(function(){\n        var current_height = $textarea.css("height").replace("px", "")*1;\n        if (current_height + 5 &lt;= $textarea.attr("scrollHeight")) {\n            $textarea.css("height", ($textarea.attr("scrollHeight") + 20));\n        }\n    });\n});\n</code></pre>\n\n<p>It\'s not very smooth but it\'s also not a client-facing application, so smoothness doesn\'t really matter.  (Had this been client-facing, I probably would have just used an auto-resize jQuery plugin.)</p>\n'}, {'answer_id': 7379509, 'author': 'Anatoly Mironov', 'author_id': 632117, 'author_profile': 'https://Stackoverflow.com/users/632117', 'pm_score': 2, 'selected': False, 'text': '<p>Like the answer of @memical.</p>\n\n<p>However I found some improvements. You can use the jQuery <code>height()</code> function. But be aware of padding-top and padding-bottom pixels. Otherwise your textarea will grow too fast.</p>\n\n<pre><code>$(document).ready(function() {\n  $textarea = $("#my-textarea");\n\n  // There is some diff between scrollheight and height:\n  //    padding-top and padding-bottom\n  var diff = $textarea.prop("scrollHeight") - $textarea.height();\n  $textarea.live("keyup", function() {\n    var height = $textarea.prop("scrollHeight") - diff;\n    $textarea.height(height);\n  });\n});\n</code></pre>\n'}, {'answer_id': 9572832, 'author': 'Eduardo Mass', 'author_id': 1250651, 'author_profile': 'https://Stackoverflow.com/users/1250651', 'pm_score': 2, 'selected': False, 'text': '<p>I\'ve made something quite easy. First I put the TextArea into a DIV. Second, I\'ve called on the <code>ready</code> function to this script.</p>\n\n<pre><code>&lt;div id="divTable"&gt;\n  &lt;textarea ID="txt" Rows="1" TextMode="MultiLine" /&gt;\n&lt;/div&gt;\n\n$(document).ready(function () {\n  var heightTextArea = $(\'#txt\').height();\n  var divTable = document.getElementById(\'divTable\');\n  $(\'#txt\').attr(\'rows\', parseInt(parseInt(divTable .style.height) / parseInt(altoFila)));\n});\n</code></pre>\n\n<p>Simple. It is the maximum height of the div once it is rendered, divided by the height of one TextArea of one row.</p>\n'}, {'answer_id': 15031691, 'author': 'Pat Murray', 'author_id': 1210319, 'author_profile': 'https://Stackoverflow.com/users/1210319', 'pm_score': 1, 'selected': False, 'text': '<p>Using ASP.NET, just simply do this:</p>\n\n<pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;\n    &lt;head&gt;\n        &lt;title&gt;Automatic Resize TextBox&lt;/title&gt;\n        &lt;script type="text/javascript"&gt;\n            function setHeight(txtarea) {\n                txtarea.style.height = txtdesc.scrollHeight + "px";\n            }\n        &lt;/script&gt;\n    &lt;/head&gt;\n\n    &lt;body&gt;\n        &lt;form id="form1" runat="server"&gt;\n            &lt;asp:TextBox ID="txtarea" runat= "server" TextMode="MultiLine"  onkeyup="setHeight(this);" onkeydown="setHeight(this);" /&gt;\n        &lt;/form&gt;\n    &lt;/body&gt;\n&lt;/html&gt;\n</code></pre>\n'}, {'answer_id': 15686827, 'author': 'user1566694', 'author_id': 1566694, 'author_profile': 'https://Stackoverflow.com/users/1566694', 'pm_score': 2, 'selected': False, 'text': '<p>My solution not using jQuery (because sometimes they don\'t have to be the same thing) is below. Though it was only tested in <a href="http://en.wikipedia.org/wiki/Internet_Explorer_7" rel="nofollow">Internet&nbsp;Explorer&nbsp;7</a>, so the community can point out all the reasons this is wrong:</p>\n\n<pre><code>textarea.onkeyup = function () { this.style.height = this.scrollHeight + \'px\'; }\n</code></pre>\n\n<p>So far I really like how it\'s working, and I don\'t care about other browsers, so I\'ll probably apply it to all my textareas:</p>\n\n<pre><code>// Make all textareas auto-resize vertically\nvar textareas = document.getElementsByTagName(\'textarea\');\n\nfor (i = 0; i&lt;textareas.length; i++)\n{\n    // Retain textarea\'s starting height as its minimum height\n    textareas[i].minHeight = textareas[i].offsetHeight;\n\n    textareas[i].onkeyup = function () {\n        this.style.height = Math.max(this.scrollHeight, this.minHeight) + \'px\';\n    }\n    textareas[i].onkeyup(); // Trigger once to set initial height\n}\n</code></pre>\n'}, {'answer_id': 16620046, 'author': 'Eduard Luca', 'author_id': 898423, 'author_profile': 'https://Stackoverflow.com/users/898423', 'pm_score': 4, 'selected': False, 'text': '<p>Probably the shortest solution:</p>\n\n<pre><code>jQuery(document).ready(function(){\n    jQuery("#textArea").on("keydown keyup", function(){\n        this.style.height = "1px";\n        this.style.height = (this.scrollHeight) + "px"; \n    });\n});\n</code></pre>\n\n<p>This way you don\'t need any hidden divs or anything like that.</p>\n\n<p>Note: you might have to play with <code>this.style.height = (this.scrollHeight) + "px";</code> depending on how you style the textarea (line-height, padding and that kind of stuff).</p>\n'}, {'answer_id': 17098236, 'author': 'Einstein47', 'author_id': 2484068, 'author_profile': 'https://Stackoverflow.com/users/2484068', 'pm_score': 1, 'selected': False, 'text': '<p>For those that are coding for IE and encounter this problem. IE has a little trick that makes it 100% CSS.</p>\n\n<pre><code>&lt;TEXTAREA style="overflow: visible;" cols="100" ....&gt;&lt;/TEXTAREA&gt;\n</code></pre>\n\n<p>You can even provide a value for rows="n" which IE will ignore, but other browsers will use. I really hate coding that implements IE hacks, but this one is very helpful. It is possible that it only works in Quirks mode.</p>\n'}]
['https://Stackoverflow.com/questions/7477', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/841/']