I see this way too often and it gets on my nerves. If you have a page that’s main purpose is a form, such as a login page, please make the page autofocus to the first field in the form. Having to tab or click on the first field is a nuisance. Even big sites make this mistake.
If you don’t care about IE you can do it as simply as:
Since autofocus
is boolean you technically don’t even need to specify an attribute value.
To do it with IE in mind you could use the following JavaScript below the form (no library needed):
Note the use of select()
so if the form reloads due to an incorrect password the field is not just in focus but the contents highlighted. There is also a setTimeout()
since IE, at least some older versions have trouble with this if it happens too quickly. 50 should be fast enough that it won’t be noticed by humans.
See how simple that is? No excuses for not fixing this 😉 .