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
| Input | Meaning | Safe representation |
|---|---|---|
/docs#intro | Fragment named intro | Keep the delimiter hash. |
/docs#section%20a | Fragment value contains a space | Encode the value, not the URL delimiter. |
/docs#section%23part | Fragment value contains a literal hash | Encode 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 /docsPHP 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.