- Attribute of
- HTML Body Tag: Master The Most Important HTML Element Now
- What does
- Fires a script when the visitor focuses on the current page.
onFocus eattribute is an event handler that instructs the browser to run a script when the page receives focus. In the context of web design, this usually means that the user has clicked on the browser window to bring the document into the foreground.
Points to be aware of
onFocus attribute is arguably more useful when used with a small area of a page, such as a form field. In this scenario, we could change the color of the field when it was in focus, and change it back when it was not. But because
body event handlers act on the entire browser window, it’s very difficult to trigger
onFocus while keeping the browser in view.
Browser Support for onFocus