HTML autofocus 属性

前へ 全ての HTML 属性 次へ

定義と用法

autofocus 属性は、ブール型属性です。

指定された場合、ページ読み込み時に、その要素が自動的にフォーカスを持つべきであることを指定します。


適用

autofocus 属性は、以下の要素で使用することができます:

要素 属性
<button> autofocus
<input> autofocus
<keygen> autofocus
<select> autofocus
<textarea> autofocus

例s

Button の例

autofocus 付きのボタン:

<button type="button" autofocus>Click Me!</button>
Try it Yourself ❯

Input の例

ページ読み込み時に、"First name" 入力フィールドが自動的にフォーカスを持つようにしてみましょう:

<form action="demo_form.html">
  First name: <input type="text" name="fname" autofocus><br>
  Last name: <input type="text" name="lname"><br>
  <input type="submit">
</form>
Try it Yourself ❯

Keygen の例

ページ読み込み時に、"Encryption" フィールドが自動的にフォーカスを持つようにしてみましょう:

<form action="demo_keygen.html" method="get">
  Username: <input type="text" name="usr_name">
  Encryption: <keygen name="security" autofocus>
  <input type="submit">
</form>
Try it Yourself ❯

Textarea の例

autofocus 付きのテキスト・エリア:

<textarea autofocus>
At w3schools.com you will learn how to make a website. We offer free tutorials in all web development technologies.
</textarea>
Try it Yourself ❯

ブラウザ・サポート

autofocus 属性は、要素ごとに以下のブラウザがサポートしています。

要素
form 5.0 10.0 4.0 5.0 9.6
input 5.0 10.0 4.0 5.0 9.6
keygen Yes Not supported Not supported 6.0 Yes
textarea Yes 10.0 4.0 Yes Yes

前へ 全ての HTML 属性 次へ