Make a Form Field Selected When Opening a Page

Have you ever wondered how to make a form field selected when going to a page. The correct terminology I guess would be how to focus on a form field on page load. However you want to say it. Here is how to make it so when a user lands on your page, the first form field you want them to fill in will already have the cursor in it.

HTML Example:


<input type=”text” name=”first” id=”first” value=”” autofocus />

<input type=”text” name=”last” id=”last” value=”” />

<input type=”submit” />



So, if you look at the above HTML example, you’ll notice the autofocus attribute was added to the first text input in the form. That will cause the focus to be on that form field when the page loads. Job done!

Leave a Reply

Your email address will not be published. Required fields are marked *