Creating auto-resize text area using JavaScript

Following is the code for creating auto resize text area using JavaScript −


 Live Demo

<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
   body {
      font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
<h1>Creating auto-resize text area</h1>
<textarea class="resizeArea"></textarea>
   let BtnEle = document.querySelector(".Btn");
   let addrEle = document.querySelectorAll(".addr");
   let resizeEle = document.querySelector(".resizeArea");
   resizeEle.addEventListener("input", resizeTextArea, false);
   function resizeTextArea() { = "auto"; = this.scrollHeight + "px";


On pasting text in the text area, the area will expand as follows −