How to pre-select an input element when the page loads in HTML5?
In this article, we are going to pre-select an input element when the page loads i.e. the user doesn’t have to click the first text box to start writing on it. When the page is loaded the input is to be pre-selected and the user can start typing directly. This can be done by using the autofocus attribute. It is a boolean attribute which brings element into focus and supports <button>, <input>, <select> and <textarea> elements.
- Create a div for the HTML form.
- We will make input elements inside a form of type text and adding autofocus to the username.
- On page load, we will see that username will be in focus, and we can directly start typing.
<input type="text" autofocus>
My Personal Notes arrow_drop_up
Please Login to comment...