--- title: focus comments: true description: '' --- Focus on a DOM element. # Syntax ```javascript .focus() .focus(options) ``` ## Usage `.focus()` requires being chained off another cy command that *yields* a DOM element. **{% fa fa-check-circle green %} Valid Usage** ```javascript cy.get('input').first().focus() // Focus on the first input ``` **{% fa fa-exclamation-triangle red %} Invalid Usage** ```javascript cy.focus('#search') // Errors, cannot be chained off 'cy' cy.window().focus() // Errors, 'window' does not yield DOM element ``` ## Arguments **{% fa fa-angle-right %} options** ***(Object)*** Pass in an options object to change the default behavior of `cy.focus`. Option | Default | Notes --- | --- | --- `log` | `true` | whether to display command in command log ## Yields `.focus()` yields the new DOM element that was focused. ## Timeout `.focus()` will continue to try to focus the element for the duration of the [`defaultCommandTimeout`](https://on.cypress.io/guides/configuration#timeouts) # Examples ## Focus **Focus on an input** ```javascript cy.get('[type="input"]').focus() ``` **Focus, type, and blur a textarea** ```javascript // yields the