2

The problem

I made an input. Now when I type, the input will adjust it's size so it fits the amount of text inside it. Now the problem is that I tried to look for some answers on the internet, but all of then expand horizontally, but I want it that when it reaches a certain point, then it will expand vertically instead of horizontally. I also DO NOT want to make a span or div with contenteditable. How can I do this?

Some code

<html>
  <body>
    <input>
  </body>
</html>
Drake Krewson
  • 69
  • 1
  • 8

1 Answers1

2

Inputs are only for single line inputs. It's not even possible to add new lines in an input.

What you're looking for is a textarea that fits the height of the content. This is possible with JavaScript:

document.querySelector('textarea').addEventListener("input", function(){
  this.style.height = '0px';
  this.style.height = this.scrollHeight + 'px';
})
<textarea></textarea>
Spectric
  • 30,714
  • 6
  • 20
  • 43