ClickStart logoHTML5 to the point

Autofocusing on a form element

You can use the autofocus attribute to automatically give focus to an input element.

Code

<input id="sample" autofocus>

If your browser does not support the autofocus attribute, you can use JavaScript to give focus to an input element:
if (!("autofocus" in document.createElement("input"))) { document.getElementById("sample").focus(); }

Example

In this example, the second form element includes the autofocus attribute.