Skip to content

Instantly share code, notes, and snippets.

@Minobi
Created October 7, 2021 13:19
Show Gist options
  • Save Minobi/8cb59e1fd28919207fa16c87dce00fdc to your computer and use it in GitHub Desktop.
Save Minobi/8cb59e1fd28919207fa16c87dce00fdc to your computer and use it in GitHub Desktop.
Textarea autoresize
<!DOCTYPE html>
<html lang="en">
<head>
<title>Textarea autoresize</title>
<style>
textarea {
resize: none;
width: 15rem;
height: 3rem;
margin: 10% 45%;
border: 1px solid gray;
border-radius: 3px;
}
</style>
</head>
<body>
<textarea spellcheck="true" placeholder="Type something long..."></textarea>
</body>
</html>
document
.getElementsByTagName('textarea')[0]
.addEventListener('input', event => {
event.target.style.height = 'initial';
event.target.style.height = `${event.target.scrollHeight}px`;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment