W3cubDocs

/Web APIs

URL: toString() method

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨April 2018⁩.

Note: This feature is available in Web Workers.

The toString() method of the URL interface returns a string containing the whole URL. It is effectively a read-only version of URL.href.

Syntax

toString()

Parameters

None.

Return value

A string.

Examples

const url = new URL(
  "https://developer.mozilla.org/en-US/docs/Web/API/URL/toString",
);
url.toString(); // should return the URL as a string

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Opera Safari Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet WebView Android WebView on iOS
toString 19 17 54 15 7 25 54 14 7 6.0 4.4 7

See also

  • The URL interface it belongs to.

© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/URL/toString