---
id: api/commands/hash
title: hash | Cypress Documentation
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: 204dffbf7fbb64b1fe8343a54ddcd869cc275f1f
updated_at: '2026-05-12T20:33:17.938Z'
---
# 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 [Learn about subject management](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Subject-Management)

*   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/1cy.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 [Learn about chaining commands](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Chains-of-Commands)

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

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

*   `cy.hash()` 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.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)
