URL Parser/ protocol · host · path · query · hash

Parse any URL into its components — protocol, hostname, port, pathname, query params, and hash — with a visual breakdown.

URL
Try an example

Did this tool solve your problem?

Code Examples

JavaScript (URL API)
const url = new URL(
  'https://user:[email protected]:8080' +
  '/v1/search?q=hello+world&page=2#results'
);

url.protocol   // 'https:'
url.username   // 'user'
url.hostname   // 'api.example.com'
url.port       // '8080'
url.pathname   // '/v1/search'
url.search     // '?q=hello+world&page=2'
url.hash       // '#results'

// Query params
url.searchParams.get('q')    // 'hello world'
url.searchParams.get('page') // '2'
[...url.searchParams]        // [['q','hello world'],['page','2']]

// Modify & rebuild
url.hostname = 'api2.example.com';
url.searchParams.set('page', '3');
url.toString() // rebuilt URL
Python
from urllib.parse import urlparse, parse_qs, urlencode

raw = 'https://user:[email protected]:8080/v1/search?q=hello+world&page=2#results'
u = urlparse(raw)

u.scheme    # 'https'
u.netloc    # 'user:[email protected]:8080'
u.hostname  # 'api.example.com'
u.port      # 8080
u.path      # '/v1/search'
u.query     # 'q=hello+world&page=2'
u.fragment  # 'results'

# Parse query params
params = parse_qs(u.query)
params['q']    # ['hello world']
params['page'] # ['2']
Go
import "net/url"

raw := "https://api.example.com:8080/search?q=hello&page=2"
u, err := url.Parse(raw)

u.Scheme   // "https"
u.Host     // "api.example.com:8080"
u.Hostname() // "api.example.com"
u.Port()     // "8080"
u.Path     // "/search"
u.RawQuery // "q=hello&page=2"

// Parse query
q := u.Query()
q.Get("q")    // "hello"
q.Get("page") // "2"

// Build URL
u2 := &url.URL{
  Scheme: "https",
  Host:   "example.com",
  Path:   "/api/v1",
}
u2.RawQuery = url.Values{"key": {"val"}}.Encode()
Shell (curl / python)
# Extract parts with grep/sed
URL="https://api.example.com/search?q=hello&page=2"

# Protocol
echo $URL | grep -oP '^[^:]+(?=://)'
# api.example.com

# Query param with Python
python3 -c "
from urllib.parse import urlparse, parse_qs
u = urlparse('$URL')
print(parse_qs(u.query))
"

# curl: show effective URL
curl -v "$URL" 2>&1 | grep '> GET'

# httpie
http GET "$URL"

Frequently Asked Questions

What are the components of a URL?
A full URL structure: scheme://username:password@hostname:port/pathname?search#hash. Each part: scheme (protocol, e.g., https, ftp), authority (username:password@hostname:port), pathname (path starting with /), search (query string starting with ?), hash (fragment identifier starting with #, not sent to server). Not all parts are required.
Is the # fragment sent to the server?
No. The hash/fragment is processed locally by the browser and never included in HTTP requests. It's used for in-page anchor navigation (scroll to a section) and in SPAs for client-side routing (e.g., React Router hash mode).
How do I correctly parse query strings?
Query string format: key=value&key2=value2. Special characters in values must be URL-encoded. Use new URLSearchParams(url.search) in JavaScript, urllib.parse.parse_qs() in Python, url.ParseQuery() in Go. Note: the same key can appear multiple times (e.g., tag=js&tag=python) — in that case the value is an array.
When can the port be omitted from a URL?
When using a protocol's default port: HTTP defaults to 80, HTTPS to 443, FTP to 21. The browser's URL API returns an empty string for url.port when the default port is used; url.host includes the port only when it differs from the default (e.g., example.com:8080).
How do I parse URLs in JavaScript?
Use the built-in URL API: const u = new URL('https://example.com/path?q=1#top'); u.hostname → 'example.com'; u.pathname → '/path'; u.searchParams.get('q') → '1'; u.hash → '#top'. The URL API works in all modern browsers and Node.js 10+, and is more reliable than regex.
What's the difference between relative and absolute URLs?
Absolute URLs include the full protocol and hostname (https://example.com/path) and can be resolved standalone. Relative URLs are relative to the current page ('./page', '/api/data', '../assets/img.png') and need a base URL to resolve. In JavaScript: new URL('./page', 'https://example.com/app/') gives https://example.com/app/page.