---
id: api/commands/root
title: root | Cypress Documentation
description: Get the root DOM element in Cypress.
section: api
source_path: docs/api/commands/root.mdx
version: 204dffbf7fbb64b1fe8343a54ddcd869cc275f1f
updated_at: '2026-05-12T20:33:17.938Z'
---
# root

Get the root DOM element.

## Syntax

```
cy.root()cy.root(options)
```

### Usage

**Correct Usage**

```
cy.root() // Yield root element <html>cy.get('nav').within(($nav) => {  cy.root() // Yield root element <nav>})
```

### Arguments

**options _(Object)_**

Pass in an options object to change the default behavior of `.root()`.

| Option | Default | Description |
| --- | --- | --- |
| `log` | `true` | Displays the command in the [Command log](/llm/markdown/app/core-concepts/open-mode.md#Command-Log) |
| `timeout` | [`defaultCommandTimeout`](/llm/markdown/app/references/configuration.md#Timeouts) | Time to wait for `cy.root()` to resolve before [timing out](#Timeouts) |

### Yields [Learn about subject management](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Subject-Management)

`cy.root()` yields the root DOM element.

The root element yielded is `<html>` by default. However, when calling `.root()` from a [`.within()`](/llm/markdown/api/commands/within.md) command, the root element will point to the element you are "within".

`cy.root()` is a query, and it is _safe_ to chain further commands.

## Examples

### HTML

#### Get the root element

```
cy.root() // yields <html>
```

### Within

#### Get the root element in a [`.within()`](/llm/markdown/api/commands/within.md) callback function

```
cy.get('form').within(($form) => {  cy.get('input[name="email"]').type('john.doe@email.com')  cy.get('input[name="password"]').type('password')  cy.root().submit() // submits the form yielded from 'within'})
```

## Rules

### Requirements [Learn about chaining commands](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Chains-of-Commands)

*   `cy.root()` requires being chained off of `cy`.

### Assertions [Learn about assertions](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Assertions)

*   `cy.root()` will automatically [retry](/llm/markdown/app/core-concepts/retry-ability.md) until all chained assertions have passed

### Timeouts [Learn about timeouts](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Timeouts)

*   `cy.root()` can time out waiting for assertions you've added to pass.

## Command Log

**_Get root element_**

```
cy.root().should('match', 'html')cy.get('.query-ul').within(() => {  cy.root().should('have.class', 'query-ul')})
```

The commands above will display in the Command Log as:

When clicking on the `root` command within the command log, the console outputs the following:

## See also

*   [`cy.get()`](/llm/markdown/api/commands/get.md)
*   [`.within()`](/llm/markdown/api/commands/within.md)
