HTML 5 autofocus feature

Here is a tutorial text

HTML5 removes the need for JavaScript solutions. If a particular input should be “selected,” or focused, by default, we can now utilize the autofocus attribute.

<input type=“text” name=“someInput” placeholder=“Douglas Quaid” required autofocus>

this is good. However can I use autofocus in multiple fields at the same time ?

That would make no sense at all. Only one item can have focus at a time. So either choose which item you want focus to fall on when the page loads, or don’t use the feature and let the user decide what to focus on. :slight_smile:

Thanks. this helped.

Out of interest, I was wondering what browsers would do if you had autofocus on more than one input. Firefox chose the first one and ignored the second. Chrome ignored the first one and put focus on the second (more what I expected).

Firefox is correct. (See step 7 in http://www.whatwg.org/specs/web-apps/current-work/multipage/association-of-controls-and-forms.html#attr-fe-autofocus )

Ha ha, if you hadn’t told me that’s what step 7 meant, I’d never have guessed. :lol: