How to set focus on an HTML input box on page load?

Spread the love

Sometimes, we want to set focus on an HTML input box on page load.

In this article, we’ll look at how to set focus on an HTML input box on page load.

How to set focus on an HTML input box on page load?

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 the input to put focus on it on page load.

Conclusion

To set focus on an HTML input box on page load, we add the autofocus attribute.

Leave a Reply

Your email address will not be published. Required fields are marked *