..

Search

autofocus

autofocus

<input> 태그의 autofocus 속성


HTML <input> 태그 ⇒


정의 및 특징

<input> 태그의 autofocus 속성은 페이지가 로드될 때 자동으로 포커스(focus)가 <input> 요소로 이동됨을 명시합니다.

 

autofocus 속성은 불리언(boolean) 속성입니다.

불리언 속성은 해당 속성을 명시하지 않으면 속성값이 자동으로 false 값을 가지게 되며, 명시하면 자동으로 true 값을 가지게 됩니다.


문법

<input autofocus>

예제
<form action="/examples/media/action_target.php" method="get">
    이름 : <input type="text" name="st_name"><br>
    학번 : <input type="text" name="st_id" autofocus><br>
    학과 : <input type="text" name="department"><br>
    <input type="submit">
</form>

코딩연습 ▶


지원하는 브라우저 및 버전

속성명

chrome

edge

ie

firefox

safari

opera

autofocus 5.0 지원함 10.0 4.0 5.0 9.6

HTML5에서 변경된 사항

autofocus 속성은 HTML5에서 <input> 태그에 새롭게 추가된 속성입니다.


HTML과 XHTML에서의 차이점

XHTML에서는 속성값을 생략할 수 없으므로, 다음과 같이 속성명과 속성값을 모두 명시해야만 합니다.

<input autofocus="autofocus" />

연습문제