How to set focus on an HTML input box on page load? Spread the love To set focus on an HTML input box on page load, we add the autofocus attribute. For instance, we write <input type="text" name="fname" autofocus /> to add the autofocus attribute to focus on the input when the page is loaded. Related