Web APIs

URL.pathname

Try the free JavaScript compiler

Reads or sets the URL path, excluding query and fragment. For ordinary HTTP(S) URLs it begins with a slash.

Formal Syntax & Structure

javascript syntaxjavascript
url.pathname

Return Value

string

Path component.

Working Example

Example Snippetjavascript
(async () => {const u=new URL("/items?q=pen#top","https://example.test/api/");console.log(u.pathname,u.search,u.hash);})()
JavaScript Reference