Autofocus in HTML5

You know what? Playing with forms and HTML5 can be really funny.

From now on no more JavaScript to autofocus a form input.

One single Attribute

Just add autofocus and it should automatically get focus when the page loads πŸ˜‰

NOTE: Several HTML5 attributes, like autofocus, can be written like this:

Autofocus Supported Browers

Google Chrome, Safari, Firefox and Opera.

We can use a short JavaScript code to create the autofocus on old versions of Internet Explorer. See the full example below.

Full HTML5 Example

Please notice the script used after the Second Input.

The code:

< !DOCTYPE html>

Autofocus Example | Developer's Blog

Form Name

First Input:

Second Input:

Back to the post

About Rick

Senior Front-end Software Engineer from Barcelona, Haidong Gumdo Instructor (korean martial art of the sword), street photographer, travel lover, TV addict, Boston Red Sox fan, and privacy advocate.

Leave a Reply

Add <code> Some Code </code> by using this tags.