Web & HTTP

URL Parser: Break Down URLs into Protocol, Host, Path, and Query

Decompose any URL into its individual components — protocol, hostname, port, path, query string, and fragment — for easy inspection.

Published January 15, 2025Updated June 1, 20254 min read

Try the free online tool

Runs entirely in your browser — no signup, no uploads.

Open Tool

URLs (Uniform Resource Locators) are structured strings made up of several distinct components: the protocol, hostname, port, path, query string, and fragment. While a URL like `https://api.example.com:8080/v1/users?role=admin&page=2#results` looks like a single string, each part carries a different meaning and is processed differently by browsers and servers.

Understanding the anatomy of a URL is essential for web development, API integration, and debugging. Misidentifying the boundary between the path and the query string, or confusing the fragment with a query parameter, leads to bugs that can be hard to trace. A URL parser makes this structure immediately visible.

This tool takes any URL — no matter how long or complex — and breaks it into a labeled table of all its components. It's useful for learning, debugging, building parsers, writing URL manipulation code, and quickly understanding what a particular URL is doing.

What Are the Components of a URL?

A URL is defined by RFC 3986 and consists of several named parts. The scheme (or protocol) comes first and identifies how the resource should be accessed — `https`, `http`, `ftp`, `mailto`, etc. The authority follows, which includes the optional username and password, the hostname (domain or IP address), and the optional port number.

After the authority comes the path, which identifies a specific resource on the server. The path is a slash-separated sequence of segments. Following the path is the optional query string, preceded by `?`, containing key-value parameters. Finally, the fragment identifier follows `#` and refers to a specific section within the resource — it is not sent to the server.

Together: `scheme://userinfo@host:port/path?query#fragment`. Not every URL uses every component — a simple `https://example.com` has a scheme, host, and an implicit root path, but no port, query, or fragment.

How to Use This Tool

Paste any URL and get an instant labeled breakdown of all its parts.

  1. 1

    Paste a URL

    Enter any URL into the input field — a full web URL, an API endpoint, a localhost URL with a port, or even a mailto or ftp URL.

  2. 2

    Click Parse

    The tool parses the URL according to RFC 3986 and identifies each component present in the URL.

  3. 3

    Review the component table

    Each identified component is displayed in a labeled row: scheme, host, port, pathname, search (query string), and hash (fragment).

  4. 4

    Inspect query parameters

    The query string is further broken down into individual key-value pairs in a separate table for easy parameter inspection.

  5. 5

    Copy individual components

    Use the copy button next to any component to copy just that part of the URL — useful when you need only the hostname or path in isolation.

Common Use Cases

URL parsing is useful in many development, debugging, and learning scenarios.

  • Debugging API client code — confirming that a programmatically constructed URL has the correct path, host, and query parameters before making a request.
  • Understanding redirect chains — parsing the `Location` header URL from a redirect response to see where you'll end up.
  • Extracting components for code — identifying the exact hostname or path segment you need to extract in a URL manipulation script.
  • Learning URL structure — seeing how different URL formats (with and without ports, credentials, or fragments) map to their components.
  • Validating URL construction — checking that a URL generated by your application is well-formed and contains all expected parts.

Tips and Best Practices

Keep these URL best practices in mind when working with URLs in code.

  • Use the built-in `URL` class in JavaScript or `urllib.parse` in Python instead of manually parsing URLs with string operations — they handle edge cases correctly.
  • Never concatenate URL paths with string concatenation — use a URL building library to avoid double slashes or missing separators.
  • Remember that the fragment (#) is not sent to the server — if you need server-side access to that value, pass it as a query parameter instead.
  • Treat the port as optional — when absent, browsers use the default port for the protocol (80 for HTTP, 443 for HTTPS).
  • Validate URLs before processing — ensure they have the required components (scheme and host at minimum) before attempting to fetch or redirect to them.

Frequently Asked Questions

What is the difference between a URL and a URI?

A URI (Uniform Resource Identifier) is the broader term for any string that identifies a resource. A URL (Uniform Resource Locator) is a type of URI that also specifies how to locate the resource — it includes a scheme like `https` or `ftp`. All URLs are URIs, but not all URIs are URLs.

Is the fragment (#) part of the URL sent to the server?

No. The fragment identifier (everything after `#`) is handled entirely by the browser and is never included in the HTTP request sent to the server. It is used for in-page navigation, client-side routing in SPAs, and linking to specific sections of a page.

What is the default port for HTTPS?

Port 443 is the default for HTTPS, and port 80 is the default for HTTP. If a URL does not specify a port, the browser uses the default for the scheme. A URL like `https://example.com:443` is equivalent to `https://example.com`.

Can a URL contain a username and password?

Yes. The URL format supports credentials in the format `scheme://username:password@host/path`. This is commonly used with FTP or basic-auth endpoints. However, embedding credentials in URLs is considered insecure because they appear in logs and browser history.

What characters are not allowed in a URL?

URLs may only contain a subset of ASCII characters. Characters outside this set — including spaces, Unicode characters, and many punctuation marks — must be percent-encoded. The safe characters are letters, digits, and a few symbols: `-`, `.`, `_`, `~`, `:`, `/`, `?`, `#`, `[`, `]`, `@`, `!`, `$`, `&`, `'`, `(`, `)`, `*`, `+`, `,`, `;`, `=`.

What is the difference between the path and the query string?

The path (`/v1/users`) identifies a specific resource or endpoint on the server and is part of the URL's hierarchical structure. The query string (`?role=admin`) passes additional parameters to the server without being part of the resource's identity. APIs often use path segments for resource IDs and query parameters for filtering or pagination.

urluriwebhttpparsing

Ready to use this tool?

Free, instant, no account required. Runs entirely in your browser.

Open Tool

More Web & HTTP Guides