HTML Attributes
HTML <textarea> autofocus Attribute
The autofocus attribute on a <textarea> places the cursor in the text box automatically on page load.
The <textarea> autofocus Attribute
autofocus is a boolean attribute for the <textarea> element. When present, the multi-line text box receives keyboard focus the moment the page loads, so the cursor is already blinking inside it and the user can begin typing immediately, which is handy for message or cover-letter fields.
Syntax
Syntax: <textarea autofocus></textarea>. It is boolean and takes no value. Use it on at most one element per page.
<label for="cover">Cover letter</label>
<textarea id="cover" name="cover" rows="6" autofocus></textarea>| Value | Description |
|---|---|
| autofocus | Present: the textarea is focused automatically on page load |
| (omitted) | Absent: no automatic focus is applied |
Auto-focusing a textarea can cause the page to scroll to it on load, pushing important content out of view on small screens. Reserve it for pages whose main purpose is that text box.
