# How to get the fragment part of a URL

> Learn how to get the fragment portion of a URL in JavaScript, the part after the # hash symbol, by reading the window.location.hash property.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2022-05-01 | Topics: [Web Platform](https://flaviocopes.com/tags/platform/) | Canonical: https://flaviocopes.com/how-to-get-fragment-part-url/

I've had the need to programmatically access the fragment part of a URL, the part of the URL after the `#` hash symbol.

For example if the URL is `index.html#second` I want `second` back.

Here's how I did it:

```js
const fragment = window.location.hash
```
