How to automatically size a textarea based on its using vanilla JavaScript
Last year, I wrote an article sharing Stephen Shaw’s awesome trick for simple, autogrowing textarea elements.
It uses a wrapper element, CSS grid, and a sprinkling of vanilla JS, and it works wonderfully! But… if your textarea has text in it when the page loads, it doesn’t work.
.autogrow { display: grid; } .autogrow::after { content: attr(data-replicated-value) " "; white-space: pre-wrap; visibility: hidden; } .autogrow textarea { resize: none; } .