Fragment encoding boundary lab · Updated November 15, 2026

Encode a URL Fragment Without Breaking the Hash

The first # separates a URL fragment; a literal hash inside the fragment value must be encoded as %23. The fragment is handled by the browser and is not sent in the HTTP request.

Three hash cases

InputMeaningSafe representation
/docs#introFragment named introKeep the delimiter hash.
/docs#section%20aFragment value contains a spaceEncode the value, not the URL delimiter.
/docs#section%23partFragment value contains a literal hashEncode the second hash as data.

Node and PHP measured output

Run date: November 15, 2026. Node.js v24.19.0 and PHP 8.5.12 expose the fragment separately from the request path.

Node.js v24.19.0 → hash #section%20a%23part, pathname /docs
PHP 8.5.12 parse_url → fragment section%20a%23part, path /docs

Common failure

Do not send a fragment expecting a server-side parameter. Browsers remove it from the HTTP request target. If the server must receive the value, place it in a query parameter and encode that value there.

FAQ

Does a fragment need URL encoding?

Its data may need encoding, but the first hash remains the fragment delimiter.

Can a server read the fragment?

Not from the request line. Client-side code can read it after navigation.

For query values, use Query Parameters. For general components, use the URL Encode tool.