Copy a link from a marketing email and paste it somewhere, and you often get something like https://shop.example.com/en/sale/shoes?size=42&colour=navy%20blue&utm_source=newsletter&utm_medium=email&utm_campaign=spring#reviews. Buried in there are the page you want, the product filters you chose, three tracking tags and an anchor that scrolls to the reviews. Reading it in an address bar is hard; editing it by hand is error-prone.
This guide breaks a URL into its parts, explains what each one does and who sees it, shows how browsers quietly normalise addresses, and covers the safe way to parse and edit URLs in code, including removing tracking parameters before you share a link.
The parts of a URL
A full URL can have up to eight components:
https://user:pass@shop.example.com:8443/en/sale/shoes?size=42&colour=navy#reviews
| Part | Value in the example |
|---|---|
| Scheme | https: |
| Userinfo | user:pass |
| Hostname | shop.example.com |
| Port | 8443 |
| Path | /en/sale/shoes |
| Query | ?size=42&colour=navy |
| Fragment | #reviews |
Scheme (protocol). https: tells the browser how to fetch the resource. Others include http:, ftp:, mailto: and file:.
Userinfo. An optional username:password@. Browsers increasingly restrict or warn about it, because it is a phishing trick (https://yourbank.com@evil.example/ actually goes to evil.example). Avoid putting credentials in URLs.
Hostname. The server's domain name or IP address. Hostnames are case-insensitive, and internationalised names such as bücher.example are converted to an ASCII form called punycode (xn--bcher-kva.example) before being sent.
Port. Optional. When omitted, the default for the scheme is used: 443 for HTTPS, 80 for HTTP.
Origin. Not a separate part of the text, but an important concept: scheme + hostname + port. Browsers use the origin for security rules such as same-origin policy and cookie scope.
Path. /en/sale/shoes identifies the resource on the server. It is case-sensitive on most servers, and it is split into segments by /.
Query string. Everything after ? and before #. It holds key=value pairs separated by &, used for filters, search terms, pagination and tracking.
Fragment (hash). Everything after #. It is never sent to the server. Browsers use it to scroll to an element with that ID, and single-page applications use it for client-side routing.
Path or query string?
Both can carry information, so which should you use? A common convention:
- Use the path for the identity of a resource:
/products/desk-lamp,/orders/1042. - Use the query for options that modify a view of it: sorting, filtering, pagination, search terms.
Search engines treat different paths as different pages, and they can treat URLs that differ only in parameters as duplicates of the same page, which is why canonical tags matter for filtered listings.
Encoding: why URLs are full of percent signs
URLs may only contain a limited set of ASCII characters. Everything else, including spaces, non-Latin letters and characters with special meaning such as &, = and # inside a value, must be percent-encoded: a % followed by two hex digits for each UTF-8 byte. A space becomes %20, é becomes %C3%A9, and a literal & inside a value becomes %26.
In query strings, a space may also be written as +, an older convention from HTML forms. Both mean the same thing to most servers. For encoding and decoding individual values, use the URL Encoder/Decoder.
Browsers normalise URLs
The address you type is not always the address the browser uses. The WHATWG URL Standard, which browsers and Node.js follow, applies several normalisations:
- the scheme and hostname are lowercased;
- a default port is removed (
https://example.com:443/becomeshttps://example.com/); .and..segments in the path are resolved (/a/../b/./cbecomes/b/c);- international domain names are converted to punycode;
- characters that must be encoded are encoded.
This matters when you compare URLs as strings, for example in redirect rules or analytics. Two URLs that look different may be the same after normalisation.
Parse and edit a URL with our tool
The URL Parser uses your browser's built-in URL parser, so what you see is exactly how a browser interprets the address.
- Open the URL Parser and paste a full address into URL, or click Load sample.
- Read the URL components table: Protocol, Username, Password, Hostname, Port (with the default noted when none is given), Origin, Path, Query string and Fragment (hash). Each has a copy button, and the protocol, hostname, port, path and fragment can be edited directly.
- Check Path segments to see each part of the path decoded.
- Under Query parameters, edit keys and values in plain decoded text, delete rows with the remove button, or click Add to create a new one. Repeated keys appear as separate rows.
- Click Copy URL to copy the rebuilt, correctly encoded address.
This is the quickest way to remove tracking tags before sharing a link: delete the utm_ rows and copy the result. To create tracking links in the first place, use the UTM Builder.
Parsing URLs in code
Never split URLs with regular expressions or indexOf. Edge cases such as encoded characters, userinfo, IPv6 hosts and missing parts make hand-written parsing fragile. JavaScript and Node.js have the standard URL class built in:
const url = new URL(
"https://shop.example.com:8443/en/sale/shoes?size=42&colour=navy%20blue&utm_source=newsletter&utm_medium=email#reviews"
);
console.log(url.hostname); // shop.example.com
console.log(url.port); // 8443
console.log(url.pathname); // /en/sale/shoes
console.log(url.searchParams.get("colour")); // navy blue
console.log(url.hash); // #reviews
// Remove every utm_* tracking parameter
for (const key of [...url.searchParams.keys()]) {
if (key.startsWith("utm_")) url.searchParams.delete(key);
}
console.log(url.href);
// https://shop.example.com:8443/en/sale/shoes?size=42&colour=navy+blue#reviews
Two details are worth noticing. The keys are copied into an array before deleting, because deleting while iterating the live list can skip entries. And once the query is modified, URLSearchParams re-serialises it using form encoding, so %20 comes back as +. Both mean a space, but if you compare URLs as strings, normalise both sides first.
Other languages have equivalents: urllib.parse in Python, java.net.URI in Java, System.Uri in .NET and parse_url in PHP. Their edge-case behaviour differs slightly from browsers, which matters for security checks such as validating redirect targets.
Tips and pitfalls
Relative URLs need a base
new URL("/pricing") throws, because a relative path has no scheme or host. Pass a base: new URL("/pricing", "https://example.com").
Validate redirects by origin, not by prefix
Checking that a redirect target "starts with https://example.com" is unsafe, because https://example.com.evil.example passes. Parse the URL and compare url.origin exactly.
Fragments do not reach the server
If a server-side script cannot see a value, check whether it is after the #. Anything in the fragment stays in the browser.
Working with the query alone
When you only have a query string, or need nested structures like filter[price][max]=50, the Query String Parser converts it to JSON and back.
Frequently asked questions
What is the difference between a URL and a URI?
A URI is any identifier for a resource; a URL is a URI that also says how to locate it, such as with https:. In everyday web development the terms are used interchangeably.
Is the part after # sent to the server?
No. The fragment is handled entirely by the browser, which is why it is used for in-page anchors and client-side routing.
Are URLs case-sensitive?
The scheme and hostname are not. The path and query usually are, depending on the server, so /About and /about can be different pages.
Why does my URL show xn-- in the domain?
That is punycode, the ASCII form of an internationalised domain name. Browsers convert names with non-ASCII characters this way before looking them up.
How do I remove tracking parameters from a link?
Delete the parameters starting with utm_ and similar tracking keys in a URL editor or in code, keeping the ones the page needs, such as product or filter parameters.