input autofocus Attribute - HTML CSS HTML Tag

HTML CSS examples for HTML Tag:input

Description

The autofocus attribute is a boolean attribute to set if an <input> element should automatically get focus when the page loads.

In XHTML, the autofocus attribute must be defined as <input autofocus="autofocus" />.

The following code shows how to Let the "First name" input field automatically get focus when the page loads:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<form action="/action_page.php">
  First name: <input type="text" name="fname" autofocus><br>
  Last name: <input type="text" name="lname"><br>
  <input type="submit">
</form><!-- w  w w . ja  v  a  2 s .  c  om-->

</body>
</html>

Related Tutorials