HTML <textarea> autofocus Attribute



The autofocus attribute of the <textarea> element is used to set the autofocus to the textarea itself when the page loads. The autofocus attribute for the <textarea> element introduced in HTML5.

Following is the syntax −

<textarea autofocus>

Let us now see an example to implement the autofocus attribute of the <textarea> element −

Example

 Live Demo

<!DOCTYPE html> <html> <body> <h2>Interview Questions</h2> <p>Why do you want go for the Technical Writer Job Profile? (100 words)</p>    <textarea rows="6" cols="70" autofocus>       Write the answer in 100 words only...    </textarea>    <p>What are your strengths? (50 words)</p>    <textarea rows="4" cols="70" autofocus>       Write the answer in 50 words only...    </textarea> </body> </html>

Output

In the above example, we have set two textarea−

<textarea rows="6" cols="70" autofocus> Write the answer in 100 words only... </textarea> <p>What are your strengths? (50 words)</p> <textarea rows="4" cols="70" autofocus> Write the answer in 50 words only... </textarea>

One of these textarea we have set with autofocus. Now whenever the page loads, the focus and the cursor will automatically be visible in the first textarea −

<textarea rows="6" cols="70" autofocus>
Updated on: 2020-06-29T08:45:49+05:30

36 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements