HTML <textarea> autofocus Attribute

The autofocus attribute on a <textarea> tag specifies that the textarea receives focus when the page has loaded.

Example

#

An autofocus attribute on a <textarea> element.
The control has focus and currently displays the blinking text entry cursor.



<form action="/tutorial/action.html">
  <textarea autofocus rows="3" cols="50" name="message" 
            placeholder="Enter your message"></textarea>
  <br/><br/>

  <input type="submit">
</form>

Using autofocus

The autofocus attribute specifies that the textarea receives focus on page load.

Only one element on a page can have the autofocus attribute.


Syntax

<textarea autofocus>

Browser support

Here is when autofocus support started for each browser:

Chrome
1.0 Sep 2008
Firefox
4.0 Mar 2011
IE/Edge
10.0 Sep 2012
Opera
1.0 Jan 2006
Safari
1.0 Jan 2003

You may also like

 Back to <textarea>
Guides