0

I have a textarea field, which I would like to automatically adjust according to number of lines used (i.e., if the user enters one line, the field height will show that line only, but if the user enters a long text, the field will show all the lines of text). I would like it to happen dynamically, without using scroll (overflow). I would appreciate help with this.

thanks

Nitai
  • 1
  • 1
  • Does this answer your question? [Creating a textarea with auto-resize](https://stackoverflow.com/questions/454202/creating-a-textarea-with-auto-resize) – Fabian S. Nov 03 '21 at 06:33
  • https://stackoverflow.com/questions/454202/creating-a-textarea-with-auto-resize/5346855#5346855 – G.L.P Nov 03 '21 at 06:33

1 Answers1

1

There are lots of ideas given in the answers pointed to in the comments so if you absolutely have to stick with textarea perhaps some of them will solve your problem but they require Javascript and I notice you have tagged CSS not JS.

So, have you considered using a contenteditable div instead? This will automatically resize depending on content without needing Javascript:

.input {
  overflow: auto;
  border: 1px solid black;
}
<div class="input" contenteditable></div>
A Haworth
  • 30,908
  • 4
  • 11
  • 14
  • Thanks. I am currently learning javascript, so if you have any suggestions containing JS, they would be appreciated – Nitai Nov 03 '21 at 09:05
  • Hi, I see you've added Javascript to your tags. I think the answers pointed to in the comments to your question give lots of ideas of how to use JS - to me they seem quite complicated! – A Haworth Nov 03 '21 at 09:15
  • Yup, to me too. but I'll give them a shot. thanks! – Nitai Nov 04 '21 at 06:06