HTML5 introduced an autofocus attribute on all web form controls. The autofocus attribute sets focus on the field that has been given the attribute as soon as the page loads. Doing this allows the user to begin typing immediately.
To include autofocus in your form you just need to add the
autofocus attribute to you input field and it will give you the desired effect.
<form> <input name="s" autofocus> <input type="submit" value="Search"> </form>
The above renders this:
If the browser doesn’t support the autofocus attribute, it will be ignored. So start using it today!
Want to become a better web developer?
Join over 25,000 other developer & designers who get awesome links to the best news and articles each week delivered directly to their inbox.