Performance: Textarea
Textarea affects page load speed minimally but can impact rendering performance when resized or when content changes dynamically.
const textarea = document.querySelector('textarea');
textarea.addEventListener('input', () => {
requestAnimationFrame(() => {
textarea.style.height = 'auto';
textarea.style.height = textarea.scrollHeight + 'px';
});
});<textarea oninput="this.style.height='auto';this.style.height=this.scrollHeight+'px'"></textarea>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Inline oninput resizing | Minimal DOM ops | 1 reflow per keystroke | Moderate paint cost | [X] Bad |
| requestAnimationFrame batching | Minimal DOM ops | 1 reflow per frame (~16ms) | Lower paint cost | [OK] Good |
<textarea> tag in HTML?<textarea> tag function<textarea> tag is designed to allow users to enter multiple lines of text, unlike <input> which is usually single line.<textarea> using HTML attributes?<textarea> size attributesrows and cols attributes define the visible height and width in lines and characters.<textarea rows='4' cols='50'></textarea> uses rows and cols correctly. Options A, B, and C use invalid or non-existent attributes.<label for='msg'>Message:</label> <textarea id='msg' rows='3' cols='20'>Hello World</textarea>
label with for='msg' links to the textarea with id='msg', so the label 'Message:' appears next to the textarea.<textarea rows='5' cols='30'>Enter your comment here</textarea
</textarea tag is missing the closing '>' character, which is required to properly close the tag.rows and cols attributes are correctly used, default text inside textarea is allowed, and textarea is not self-closing.<label> with for attribute matching the textarea's id helps screen readers and keyboard users.em or % makes the textarea adapt to different screen sizes.Pass the test and this pattern moves unknown