HTML <入力>オートフォーカス属性
例
ページが読み込まれたときに、「名」入力フィールドに自動的にフォーカスが移るようにします。
<form action="/action_page.php">
<label for="fname">First name:</label>
<input type="text" id="fname"
name="fname" autofocus><br><br>
<label for="lname">Last
name:</label>
<input type="text" id="lname" name="lname"><br><br>
<input type="submit">
</form>
定義と使用法
autofocus
属性はブール属性です。
<input>
存在する場合、ページの読み込み時に要素が自動的にフォーカスを取得するように指定します。
ブラウザのサポート
表の数字は、属性を完全にサポートする最初のブラウザーバージョンを示しています。
Attribute | |||||
---|---|---|---|---|---|
autofocus | 5.0 | 11.0 | 4.0 | 5.0 | 9.6 |
構文
<input autofocus>
HTML <input>タグ