Have you ever wanted to automatically place the cursor in a field when the page is rendered? I know I have.

This sort of thing used to require more than just HTML to accomplish but with now HTML5 it’s a breeze. Here’s how you can autofocus fields with HTML5 form attributes.

Yep, it’s that easy. HTML5 form attributes have pretty good browser support and older browsers that don’t support them will simply ignore them.

It can be added in the following ways:

  • autofocus
  • autofocus=""
  • autofocus="autofocus"

All three do the exact same thing.


Browser Support

ie10 and aboveChrome 31 and aboveFire Fox 26 and aboveOpera 19 and above5.1 and above

HTML5 autofocus has pretty good browser support working in all modern browsers. Not supported in ie9 and below.


Sources

Comments