---
id: api/commands/hash
title: cy.hash()
description: Get the current URL hash of the page that is currently active in Cypress.
section: api
source_path: docs/api/commands/hash.mdx
version: 475685366f7f73d62514764c71d1dcf13e7eb276
updated_at: '2026-09-19T00:22:08.216Z'
---
# hash

Get the current URL hash of the page that is currently active.

This is an alias of [`cy.location('hash')`](/llm/markdown/api/commands/location.md)

## Syntax

```
cy.hash()
cy.hash(options)
```

### Usage

**Correct Usage**

```
cy.hash() // Get the url hash
```

### Arguments

**options _(Object)_**

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

**cy.hash( _options_ )**

| 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.hash()` to resolve before [timing out](#Timeouts) |

### Yields

*   When the current URL contains a hash, `cy.hash()` yields the current URL's hash (including the `#` character).
*   When the current URL does not contain a hash, `cy.hash()` yields an empty string.
*   `cy.hash()` is a query, and it is _safe_ to chain further commands.

## Examples

### No Args

#### Assert that hash is `#/users/1` given remote URL: `http://localhost:8000/app/#/users/1`

```
// yields #/users/1
cy.hash().should('eq', '#/users/1') // => true
```

#### Assert that the hash matches via RegExp

```
<ul id="users">
  <li>
    <a href="#/users/8fc45b67-d2e5-465a-b822-b281d9c8e4d1">Fred</a>
  </li>
</ul>
```

```
cy.get('#users li').find('a').click()
cy.hash().should('match', /users\/.+$/) // => true
```

## Rules

### Requirements

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

### Assertions

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

### Timeouts

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

## Command Log

**_Assert that the hash matches `#users/new`_**

```
cy.hash().should('eq', '#users/new')
```

The commands above will display in the Command Log as:

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

## See also

*   [`cy.location()`](/llm/markdown/api/commands/location.md)
*   [`cy.url()`](/llm/markdown/api/commands/url.md)
