Skip to content

Instantly share code, notes, and snippets.

@kobitoDevelopment
Created November 11, 2025 12:07
Show Gist options
  • Select an option

  • Save kobitoDevelopment/523a641849028db6f9324de3d6b88a7b to your computer and use it in GitHub Desktop.

Select an option

Save kobitoDevelopment/523a641849028db6f9324de3d6b88a7b to your computer and use it in GitHub Desktop.
.auto-resize {
max-width: 640px;
width: 100%;
max-height: 320px;
resize: none;
overflow-y: auto;
}
<textarea class="auto-resize"></textarea>
document.addEventListener('DOMContentLoaded', () => {
const textarea = document.querySelector('.auto-resize');
function adjustHeight() {
textarea.style.height = 'auto';
textarea.style.height = textarea.scrollHeight + 'px';
}
textarea.addEventListener('input', adjustHeight);
window.addEventListener('resize', adjustHeight);
adjustHeight();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment