{
  "doc": {
    "id": "api/commands/root",
    "title": "root | Cypress Documentation",
    "description": "Get the root DOM element in Cypress.",
    "section": "api",
    "source_path": "/llm/markdown/api/commands/root.md",
    "version": "3cf5b86b3403f604bdf7f3e35025c3bc3865e02c",
    "updated_at": "2026-05-07T17:44:31.931Z",
    "headings": [
      {
        "id": "api/commands/root#root",
        "text": "root",
        "level": 1
      },
      {
        "id": "api/commands/root#syntax",
        "text": "Syntax",
        "level": 2
      },
      {
        "id": "api/commands/root#usage",
        "text": "Usage",
        "level": 3
      },
      {
        "id": "api/commands/root#arguments",
        "text": "Arguments",
        "level": 3
      },
      {
        "id": "api/commands/root#yields-learn-about-subject-management",
        "text": "Yields Learn about subject management",
        "level": 3
      },
      {
        "id": "api/commands/root#examples",
        "text": "Examples",
        "level": 2
      },
      {
        "id": "api/commands/root#html",
        "text": "HTML",
        "level": 3
      },
      {
        "id": "api/commands/root#get-the-root-element",
        "text": "Get the root element",
        "level": 4
      },
      {
        "id": "api/commands/root#within",
        "text": "Within",
        "level": 3
      },
      {
        "id": "api/commands/root#get-the-root-element-in-a-within-callback-function",
        "text": "Get the root element in a .within() callback function",
        "level": 4
      },
      {
        "id": "api/commands/root#rules",
        "text": "Rules",
        "level": 2
      },
      {
        "id": "api/commands/root#requirements-learn-about-chaining-commands",
        "text": "Requirements Learn about chaining commands",
        "level": 3
      },
      {
        "id": "api/commands/root#assertions-learn-about-assertions",
        "text": "Assertions Learn about assertions",
        "level": 3
      },
      {
        "id": "api/commands/root#timeouts-learn-about-timeouts",
        "text": "Timeouts Learn about timeouts",
        "level": 3
      },
      {
        "id": "api/commands/root#command-log",
        "text": "Command Log",
        "level": 2
      },
      {
        "id": "api/commands/root#see-also",
        "text": "See also",
        "level": 2
      }
    ]
  },
  "chunks": [
    {
      "id": "api/commands/root#syntax",
      "doc_id": "api/commands/root",
      "heading": "Syntax",
      "heading_level": 2,
      "content_markdown": "## Syntax\n\n```\ncy.root()cy.root(options)\n```\n\n### Usage\n\n**Correct Usage**\n\n```\ncy.root() // Yield root element <html>cy.get('nav').within(($nav) => {  cy.root() // Yield root element <nav>})\n```\n\n### Arguments\n\n**options _(Object)_**\n\nPass in an options object to change the default behavior of `.root()`.\n\n| Option | Default | Description |\n| --- | --- | --- |\n| `log` | `true` | Displays the command in the [Command log](/llm/markdown/app/core-concepts/open-mode.md#Command-Log) |\n| `timeout` | [`defaultCommandTimeout`](/llm/markdown/app/references/configuration.md#Timeouts) | Time to wait for `cy.root()` to resolve before [timing out](#Timeouts) |\n\n### Yields [Learn about subject management](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Subject-Management)\n\n`cy.root()` yields the root DOM element.\n\nThe 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\".\n\n`cy.root()` is a query, and it is _safe_ to chain further commands.\n",
      "section": "api",
      "anchors": [
        "syntax"
      ],
      "path": "/llm/json/chunked/api/commands/root.json",
      "token_estimate": 180
    },
    {
      "id": "api/commands/root#arguments",
      "doc_id": "api/commands/root",
      "heading": "Arguments",
      "heading_level": 3,
      "content_markdown": "### Arguments\n\n**options _(Object)_**\n\nPass in an options object to change the default behavior of `.root()`.\n\n| Option | Default | Description |\n| --- | --- | --- |\n| `log` | `true` | Displays the command in the [Command log](/llm/markdown/app/core-concepts/open-mode.md#Command-Log) |\n| `timeout` | [`defaultCommandTimeout`](/llm/markdown/app/references/configuration.md#Timeouts) | Time to wait for `cy.root()` to resolve before [timing out](#Timeouts) |\n",
      "section": "api",
      "anchors": [
        "arguments"
      ],
      "path": "/llm/json/chunked/api/commands/root.json",
      "token_estimate": 79
    },
    {
      "id": "api/commands/root#yields-learn-about-subject-management",
      "doc_id": "api/commands/root",
      "heading": "Yields Learn about subject management",
      "heading_level": 3,
      "content_markdown": "### Yields [Learn about subject management](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Subject-Management)\n\n`cy.root()` yields the root DOM element.\n\nThe 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\".\n\n`cy.root()` is a query, and it is _safe_ to chain further commands.\n",
      "section": "api",
      "anchors": [
        "yields-learn-about-subject-management"
      ],
      "path": "/llm/json/chunked/api/commands/root.json",
      "token_estimate": 68
    },
    {
      "id": "api/commands/root#examples",
      "doc_id": "api/commands/root",
      "heading": "Examples",
      "heading_level": 2,
      "content_markdown": "## Examples\n\n### HTML\n\n#### Get the root element\n\n```\ncy.root() // yields <html>\n```\n\n### Within\n\n#### Get the root element in a [`.within()`](/llm/markdown/api/commands/within.md) callback function\n\n```\ncy.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'})\n```\n",
      "section": "api",
      "anchors": [
        "examples"
      ],
      "path": "/llm/json/chunked/api/commands/root.json",
      "token_estimate": 56
    },
    {
      "id": "api/commands/root#rules",
      "doc_id": "api/commands/root",
      "heading": "Rules",
      "heading_level": 2,
      "content_markdown": "## Rules\n\n### Requirements [Learn about chaining commands](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Chains-of-Commands)\n\n*   `cy.root()` requires being chained off of `cy`.\n\n### Assertions [Learn about assertions](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Assertions)\n\n*   `cy.root()` will automatically [retry](/llm/markdown/app/core-concepts/retry-ability.md) until all chained assertions have passed\n\n### Timeouts [Learn about timeouts](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Timeouts)\n\n*   `cy.root()` can time out waiting for assertions you've added to pass.\n",
      "section": "api",
      "anchors": [
        "rules"
      ],
      "path": "/llm/json/chunked/api/commands/root.json",
      "token_estimate": 65
    },
    {
      "id": "api/commands/root#command-log",
      "doc_id": "api/commands/root",
      "heading": "Command Log",
      "heading_level": 2,
      "content_markdown": "## Command Log\n\n**_Get root element_**\n\n```\ncy.root().should('match', 'html')cy.get('.query-ul').within(() => {  cy.root().should('have.class', 'query-ul')})\n```\n\nThe commands above will display in the Command Log as:\n\nWhen clicking on the `root` command within the command log, the console outputs the following:\n",
      "section": "api",
      "anchors": [
        "command-log"
      ],
      "path": "/llm/json/chunked/api/commands/root.json",
      "token_estimate": 52
    }
  ]
}