Using the HTML autofocus attribute
The Boolean autofocus attribute gives a form control focus when the page loads:
<input type="text" autofocus>
It works on <input>, <button>, <select>, and <textarea> elements.
Use it deliberately. Moving focus automatically can surprise keyboard and screen-reader users, and on mobile it may open the on-screen keyboard as soon as the page appears. It makes sense for a page built around one obvious task, such as a search screen. On a normal page, I would usually let the reader decide where to start.