Location hash Property

Get the anchor part of the URL

Definition and Usage

The location.hash property sets or returns the anchor part of a URL, including the hash sign (#).

Note

When location.hash is used to set the anchor part, do not include the hash sign (#).

Syntax

Return the hash property:

location.hash

Set the hash property:

location.hash = anchorname

Parameters

Parameter Description
anchorname The anchor part of a URL.

Return Value

Type Description
A stringThe anchor part of the URL, including the hash sign (#).

Browser Support

location.hash is supported in all browsers:
Chrome IE Edge Firefox Safari Opera
Yes Yes Yes Yes Yes Yes