URL Structure Explained: Every Part of a Web Address

May 28, 20266 min read

What Is a URL?

A URL (Uniform Resource Locator) is the address you type into a browser to reach a specific resource on the internet. Every web page, image, and API endpoint has one. Understanding URL structure helps you debug routing issues, build correct links, and communicate with APIs confidently.

RFC 3986 defines the general syntax:

scheme://authority/path?query#fragment

Each part serves a distinct purpose. Let's break them down.

The Components of a URL

Here is a complete URL with every possible component:

https://user:pass@example.com:8080/docs/api?q=hello&lang=en#results
ComponentFormatExampleRequired?
Schemeprotocol:https:Yes
User Infouser:pass@user:pass@No
Hostnamedomain or IPexample.comYes
Port:number:8080No
Path/segment/.../docs/apiNo (defaults to /)
Query?key=value&...?q=hello&lang=enNo
Fragment#identifier#resultsNo

Scheme (Protocol)

The scheme tells the browser which protocol to use. The two most common schemes on the web are http and https. Other examples include ftp, mailto, file, and ws (WebSocket).

https://example.com
^^^^^^
scheme

Always use https in production. Modern browsers flag http sites as insecure, and search engines rank HTTPS pages higher.

Authority (Host and Port)

The authority section contains the hostname, optional port, and optional user info. It tells the browser where to connect.

Hostname

The hostname identifies the server. It can be a domain name or an IP address.

https://example.com       → domain name
https://192.168.1.1       → IPv4 address
https://[::1]             → IPv6 address (brackets required)

Port

Ports differentiate services running on the same machine. Most of the time you omit them because browsers use default ports:

SchemeDefault Port
HTTP80
HTTPS443
FTP21

You only specify a port when it differs from the default:

https://example.com:8080   → custom port
https://example.com        → defaults to 443

User Info

Rarely seen in browsers, user info appears in database URLs and internal service addresses:

postgresql://admin:secret@db.internal:5432/mydb

Avoid putting credentials in URLs for public-facing applications. They appear in server logs, browser history, and referrer headers.

Path

The path identifies a specific resource on the server. It resembles a filesystem path but is defined by the server's routing logic — not an actual file on disk.

https://example.com/docs/api/users
                     ^^^^^^^^^^^^^^
                     path

Paths are case-sensitive on most servers. /Docs and /docs may point to different resources.

Path Encoding

Certain characters in paths require percent-encoding:

CharacterEncodedReason
Space%20Spaces are illegal in URLs
%%25The percent sign starts an encoding
Non-ASCII%XX%XXUnicode uses UTF-8 byte encoding

Use hyphens - instead of spaces or underscores in URL paths for better readability and SEO.

Query String

The query string passes data to the server. It starts with ? and contains key-value pairs separated by &:

?q=hello&lang=en&page=2
^                     ^
start                end

Query parameters handle search terms, filters, pagination, and tracking codes. For a deep dive into encoding and best practices, see our Query Parameters Guide.

Fragment

The fragment (or anchor) points to a specific section within a page:

https://example.com/docs#installation
                     ^^^^^^^^^^^^^^^^
                     fragment

Key facts about fragments:

  • The browser never sends the fragment to the server
  • JavaScript reads it via window.location.hash
  • Clicking a fragment link scrolls the page without a full reload

Relative vs Absolute URLs

URLs come in two forms:

TypeExampleWhen to Use
Absolutehttps://example.com/docs/apiExternal links, cross-origin references
Relative/docs/api or ../apiInternal links within the same site

Relative URLs resolve against the current page's base URL. Use relative paths for internal navigation — they survive domain changes and work across environments.

<!-- Absolute — breaks if domain changes -->
<a href="https://example.com/about">About</a>

<!-- Relative — works on any domain -->
<a href="/about">About</a>

Internationalized Domain Names (IDN)

Domain names can contain non-ASCII characters like münchen.de or 中国.cn. Browsers display the Unicode form but send the ASCII-compatible encoding (Punycode) to DNS:

Display: münchen.de
Actual:  xn--mnchen-3ya.de

You must register the Punycode version with your DNS provider. Most registrars handle this conversion automatically.

Common URL Pitfalls

Default Port Confusion

Omitting a default port and specifying it produce the same origin:

https://example.com       ← same origin →
https://example.com:443

But non-default ports create different origins:

https://example.com       ← different origin →
https://example.com:8443

This matters for CORS, cookies, and localStorage.

Path Encoding Differences

Not all encoded paths are equivalent. Some servers decode %2F (/) in paths, while others treat it as a literal character:

/api/users%2Fadmin   → might route to /api/users/admin or to /api/users%2Fadmin

Avoid encoding slashes in path segments. If you need slashes as data, use query parameters instead.

Trailing Slashes

/docs/ and /docs may resolve to different resources depending on the server. Most frameworks redirect one to the other, but inconsistent handling causes duplicate content issues in search engines.

Pick one convention and enforce it across your application.

Key Takeaways

  • URLs consist of scheme, authority, path, query, and fragment
  • Default ports (80 for HTTP, 443 for HTTPS) can be omitted
  • Paths are case-sensitive and require percent-encoding for special characters
  • Fragments never reach the server — they are client-side only
  • Use relative URLs for internal links to survive domain changes
  • IDN domains use Punycode under the hood — register the ASCII form with DNS
  • Trailing slashes and encoded slashes can cause subtle routing bugs

Try It Yourself

Parse any URL into its components with our free URL Parser tool. Paste a full URL and instantly see the scheme, host, port, path, query parameters, and fragment broken down for you.