# How to get the current URL with JavaScript

By Atta Ur Rehman Shah (https://attacomsian.com/about). Published Sep 18, 2021. Topics: JavaScript.
Canonical URL: https://attacomsian.com/blog/javascript-current-url

> A short guide to learn how to get the current web page URL using JavaScript.

The `window.location.href` property can be used to get the entire URL of the current web page, including hostname, query string parameters, protocol, and fragment identifier.

```javascript
const url = window.location.href;

console.log(url);
// https://attacomsian.com/blog/javascript-current-url
```

The `Location` object can also be accessed without the `window` prefix:

```javascript
const url = location.href;
```

Take a look at [JavaScript location object](https://attacomsian.com/blog/javascript-location-object) tutorial to learn more about the `Location` object properties and methods.
