Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to resize textarea based on its value?

I want to scale a textarea based on its content, for example:

textarea {
  height: auto;
}
<textarea>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Commodi illum obcaecati alias, quaerat enim eos esse corrupti ducimus eius saepe, odio dignissimos nihil dicta sunt cum voluptas quae magni reiciendis labore velit aliquid asperiores iure? Non laboriosam eaque quis voluptatibus recusandae doloribus, suscipit, at dignissimos, dicta voluptates corporis nisi! Voluptatem?
</textarea>

Hopefully you can find a solution

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Unfortunately, there is no great way to do it with raw HTML or CSS, JavaScript is typically the solution especially with using the textarea element. However, you can use the contentEditable feature on a div, which will make it so the textbox automatically resizes based on content.

div {
  outline: solid 1px;
  width: 120px;
}
<div contentEditable></div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading