Web APIs

URL.hash

Try the free JavaScript compiler

Reads or sets the fragment of a URL object. Modifying a detached URL does not navigate the document.

Formal Syntax & Structure

javascript syntaxjavascript
url.hash

Return Value

string

Fragment including #, or empty string.

Working Example

Example Snippetjavascript
(async () => {const u=new URL("https://example.test/guide#part");u.hash="next";console.log(u.hash,u.pathname);})()
JavaScript Reference