W3cubDocs

/Web APIs

URL: pathname property

The pathname property of the URL interface represents a location in a hierarchical structure. It is a string constructed from a list of path segments, each of which is prefixed by a / character. If the URL has no path segments, the value of its pathname property will be the empty string.

URLs such as https and http URLs that have hierarchical schemes (which the URL standard calls "special schemes") always have at least one (invisible) path segment: the empty string. Thus the pathname value for such "special scheme" URLs can never be the empty string, but will instead always have a least one / character.

For example, the URL https://developer.mozilla.org has just one path segment: the empty string, so its pathname value is constructed by prefixing a / character to the empty string.

Some systems define the term slug to mean the final segment of a non-empty path if it identifies a page in human-readable keywords. For example, the URL https://example.org/articles/this-that-other-outre-collection has this-that-other-outre-collection as its slug.

Some systems use the ; and = characters to delimit parameters and parameter values applicable to a path segment. For example, with the URL https://example.org/users;id=42/tasks;state=open?sort=modified, a system might extract and use the path segment parameters id=42 and state=open from the path segments users;id=42 and tasks;state=open.

Note: This feature is available in Web Workers

Value

A string.

Examples

js

const url = new URL(
  "https://developer.mozilla.org/en-US/docs/Web/API/URL/pathname?q=value",
);
console.log(url.pathname); // Logs "/en-US/docs/Web/API/URL/pathname"

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
pathname 32 13
22Before Firefox 53, pathname and search returned wrong values for custom protocols. Given protocol:host/x?a=true&b=false, pathname would return "/x?a=true&b=false" and search would return "", rather than "/x" and "?a=true&b=false" respectively. See bug 1310483.
No 19 10 4.4.3 32
22Before Firefox 53, pathname and search returned wrong values for custom protocols. Given protocol:host/x?a=true&b=false, pathname would return "/x?a=true&b=false" and search would return "", rather than "/x" and "?a=true&b=false" respectively. See bug 1310483.
19 10 2.0

See also

  • The URL interface it belongs to.

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