HTML5 giới thiệu thuộc tính mới autofocus dùng như sau:
<input type = "text" name = "search" autofocus/>
Thuộc tính này được hỗ trợ bởi phiên bản mới của Mozilla, Safari và Chrome.
Ví dụ
Chạy mã sau để học autofocus:
<!DOCTYPE HTML> <html> <body> <form action = "/cgi-bin/html5.cgi" method = "get"> Nhập email : <input type = "text" name = "newinput" autofocus/> <p>Thử submit bằng nút Submit</p> <input type = "submit" value = "submit" /> </form> </body> </html>