MyInternships.in

HTML Attributes

HTML <textarea> autofocus Attribute

The autofocus attribute on a <textarea> places the cursor in the text box automatically on page load. It is a boolean attribute, so it needs no value.


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.

The basic pattern
Example
<textarea autofocus></textarea>

Example

Run the example — the cover-letter box is focused on load, so you can start typing immediately.

Focus a cover-letter box on load
Example
<!DOCTYPE html>
<html>
  <body>
    <form>
      <label for="cover">Cover letter</label><br>
      <textarea id="cover" name="cover" rows="6" cols="40"
                placeholder="Start typing your cover letter..." autofocus></textarea>
    </form>
  </body>
</html>

Attribute Values

ValueDescription
autofocusPresent: 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.

Key Takeaways

  • autofocus is a boolean attribute usable on <textarea>.
  • It puts the cursor in the text box as soon as the page loads.
  • It is handy for message and cover-letter fields.
  • Use it on at most one element per page.
  • Avoid it when it would scroll key content off small screens.

Related HTML Topics

Keep learning with these closely related tutorials.

Ready to use your HTML skills?

Find web development internships and fresher jobs across India.

Browse Web Dev Internships