{
  "doc": {
    "id": "api/commands/root",
    "title": "cy.root()",
    "description": "Get the root DOM element in Cypress.",
    "section": "api",
    "source_path": "/llm/markdown/api/commands/root.md",
    "version": "29f95bf8bb06f320986f3749f5bf09a35a409eab",
    "updated_at": "2026-09-04T10:49:54.630Z",
    "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",
        "text": "Yields",
        "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",
        "text": "Requirements",
        "level": 3
      },
      {
        "id": "api/commands/root#assertions",
        "text": "Assertions",
        "level": 3
      },
      {
        "id": "api/commands/root#timeouts",
        "text": "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()\ncy.root(options)\n```\n\n### Usage\n\n**Correct Usage**\n\n```\ncy.root() // Yield root element <html>\ncy.get('nav').within(($nav) => {\n  cy.root() // Yield root element <nav>\n})\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\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": 179
    },
    {
      "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",
      "doc_id": "api/commands/root",
      "heading": "Yields",
      "heading_level": 3,
      "content_markdown": "### Yields\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"
      ],
      "path": "/llm/json/chunked/api/commands/root.json",
      "token_estimate": 63
    },
    {
      "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) => {\n  cy.get('input[name=\"email\"]').type('john.doe@email.com')\n  cy.get('input[name=\"password\"]').type('password')\n  cy.root().submit() // submits the form yielded from 'within'\n})\n```\n",
      "section": "api",
      "anchors": [
        "examples"
      ],
      "path": "/llm/json/chunked/api/commands/root.json",
      "token_estimate": 57
    },
    {
      "id": "api/commands/root#rules",
      "doc_id": "api/commands/root",
      "heading": "Rules",
      "heading_level": 2,
      "content_markdown": "## Rules\n\n### Requirements\n\n*   `cy.root()` requires being chained off of `cy`.\n\n### 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\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": 52
    },
    {
      "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')\n\ncy.get('.query-ul').within(() => {\n  cy.root().should('have.class', 'query-ul')\n})\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": 55
    }
  ]
}