Cloud Cloud Cloud Cloud

The autofocus Attribute

The Current State of HTML5 Forms

Let Wufoo do the hard work. Sign up for a free account and start making forms the easy way.

Live Demo



 


Firefox
4+

Safari
5+

Safari
5-

Chrome
6+

Opera
11+

IE
10+

Android
3+

The Low Down

The first input or textarea in source order that has the autofocus attribute will be focused on page load.

  • In browsers without autofocus support, no fields will be focused on page load, unless otherwise given focus with JavaScript.
  • Originally in the specification, the last element with the autofocusattribute received focus. Safari still does this. IE, Firefox, Chrome and Opera focus on the first occurence of the attribute.
  • Warning: this attribute will force a page scroll to the field with the autofocus attribute set, even within an iframe. So: know your audience, know the position of the form.
  • If you use a fallback, make sure to fire it on DOM ready rather than onwindow.load. Would be way jarring to have the page position jump after a user may already be interacting with the page.
  • It’s probably good that Mobile WebKit doesn’t support the autofocusattribute as the zooming/keyboard opening would be too in-your-face in most circumstances.
  • Recommendation: Don’t use this attribute.
Cloud Cloud Cloud Cloud

Let Wufoo do the hard work.

Sign up for a free account and start making forms the easy way.

Our Cookie Policy and Privacy Policy outline how we use cookies to help optimize service, personalize content, tailor and measure our marketing, and improve your user experience. I agree to use of cookies for these purposes.