It is recommended to add a step to calculate the thickness, which can correctly handle the border width on the input box and avoid unexpected scrolling.
textarea.oninput = function () { textarea.style.height = 'auto' const thickness = textarea.offsetHeight - textarea.clientHeight textarea.style.height = `${textarea.scrollHeight + thickness}px`}