What are the parts of a URL?  |  Articles  |  web.dev (2024)

What are the parts of a URL? | Articles | web.dev (1)

Sam Dutton

Most of the time it's fine to say things like "I bought a domain" or "Our imagesare hosted on a different site", even if that's not strictly true. However, insome contexts it's necessary to be more precise. For example, when dealing withcookies, you need to understand the difference between site and origin.

Names for URL parts are specified in a standard, which also defines a JavaScriptAPI:

  • The URL standard defines URLs and relatedconcepts to enable engineers to build interoperable web browsers.
  • The URL API componentof the standard defines methods to provide access to parts of a URL string,such as the scheme or origin.

This document explains a range of terms used with HTTP or HTTPS URL strings. Itdoes not cover other types of URL such as file or data URLs. For terms such ashost and origin, accurate definitions are inherently complex, so thisdocument provides examples and links to the URL standard, rather thanattempting full explanations.

You can use JavaScript to get the names of URL components that are defined bythe URL API. For example:

let url = new URL('https://foo.com.au:1234/bar/foo.html#bar');console.log(url);

URL analyzer

Edit the URL below to see how parts of the URL string are named.You can also open this in a separate tab aturl-parts.glitch.me.

Names for URL parts are listed alphabetically below.

Country-code top-level domain (ccTLD)

A top-level domain defined in the ISO 3166-1 Country Codes list.

  • For https://example.org.au, the ccTLD is au.
  • For https://example.io, the ccTLD is io.

Domain name

The parts of an HTTP or HTTPS URL separated by dots: everything after thescheme, but before the path or port(if specified). Each part of the domain name is known as a label.

URL Domain name
https://example.github.io/path example.github.io
https://support.example.org.au:443 support.example.org.au

Effective top-level domain (eTLD)

An entry in the Public Suffix List, includinga TLD and(for eTLDs with multiple parts) additional domains below that:second-level, third-level, and so on.

  • For example: com, com.au, github.io, sa.edu.au,schools.nsw.edu.au.

A "public suffix", such as these examples, is a name under which domains can beregistered. The Public Suffix List is a list of all known public suffixes, andis frequently updated. Browsers including Chromiumand Firefoxuse the list in their builds.

eTLD+1

See registrable domain.

An eTLD plus the subdomain that precedes it.

  • For example: example.com, example.org.au, example.github.io,example.sa.edu.au, example.schools.nsw.edu.au.

Filename

Not defined in the URL standard, and not part of the URL API, but commonly usedto refer to the final, non-path, part of the URL based onthe—often incorrect—assumption that the URL maps directly to a directorystructure.

For example, with https://example.com/dir/file.html, file.html might be referred to as the filename.

The filename value is also used by browsers to name an asset if it's downloaded.For example, https://example.com/images/image.jpg would typically be savedlocally to image.jpg.

Fragment

A string following a # character at the end of a URL that provides afragment identifier.

  • For example: the URL https://example.com/cats#tabby has a fragmentidentifier value of tabby.

The part including the # is known as the hash or anchor.You can also link to and highlight a text fragment.

The hash is returned by the URL API rather than the fragment.

Fully-qualified domain name (FQDN)

A complete address for a website or a server, that maps to an IP address.

URL FQDN
https://example.com:1234/cats example.com
https://api.example.github.io api.example.github.io

The FQDN for a URL does not include the port, even if a non-defaultport is used.

Hash (or anchor)

A string following a # character at the end of a URL that provides afragment identifier.(Insome contextsthis is referred to as an "anchor".)

The part excluding the # is known as the fragment.You can also link to and highlight a text fragment.

The hash is returned by the URL API rather than the fragment.

Host

As defined in the URL standard, a host can be adomain name, IP v4 address, IPv6 address, opaque host, or emptyhost.

  • The URL standard's definition of host does not include the port.
  • URL.host includesthe port, unless the port is the default for the scheme.
  • URL.hostname does not includethe port.
URL URL.host
https://www.example.com:443/cat www.example.com
// 443 is the default port for the scheme
https://www.example.com:1234/cat www.example.com:1234
https://cat.example.github.io cat.example.github.io

Hostname

Hostname is defined by the JavaScript URL API, but not elsewhere by the URLstandard. See host representation for more detail.

URL.hostname returns the host without the port.

URL URL.hostname
https://www.example.com:443/cat www.example.com
https://www.example.com:1234/cat www.example.com
https://cat.example.github.io cat.example.github.io

Origin

The URL standard defines origin, andlinks to the HTML standard forbackground.

For HTTP or HTTPS URLs, URL.origin returns the scheme, the host, and port (unless the port is the defaultfor the scheme).

URL URL.origin
https://www.example.com:443/cat https://www.example.com
https://www.example.com:1234/cat https://www.example.com:1234
https://cat.example.github.io https://cat.example.github.io

Parameter

See Search params

Password

See username.

Pathname

For an HTTP or HTTPS URL, the part after the domain and port (if defined),including a filename (if defined) but not including thesearch string or hash.

URL URL.pathname
https://example.com [empty string]
https://example.com:8000/search?q=tabby /search
https://example.github.io/cat/pattern#tabby /cat/pattern
https://example.github.io/README.md /README.md

"Path" is sometimes used to refer to the pathname without the filename. For example, for the URL https://example.com/cat/pattern/tabby.html, the "path" is /cat/pattern.

Port

The number after a : in a URL that identifies a network port. For example: forthe URL https://example.com:1234/tabby the port number is 1234.

The port number must be a 16-bit unsigned integer: in other words, an integerbetween 0 and 65535 inclusive.

For an HTTP URL, the default port is 80; for HTTPS, the default is 443. A URLdoes not need to specify the port number unless a non-default port is used.

The API returns an empty string if the port is the default for the scheme.

URL URL.port
https://example.com // empty string
https://example.com:443/foo // empty string: port is default for scheme
https://www.example.com:1234/foo 1234

Protocol

The scheme followed by : (for example http: or https:).

protocol is available from the URL API, but scheme is not.

Query (or "query string")

The search portion of the URL, excluding the leading ?.

Registrable domain

  • For a URL with a single-part eTLD such as com or org (i.e. aneTLD that corresponds to a TLD), the domain and thesecond-level domain before it: for example, example.com orexample.org.
  • For a URL with a two-part eTLD where only third-level registration isallowed (i.e. entries in the Public Suffix List such as com.au and, github.io) thetwo-part top-level domain ("public suffix") and the third-level domain namejust before that. For example: example.org.au or example.github.io.
  • For eTLDs with three or more parts, the eTLD and the domain before that.

Scheme

The part of the URL (before ://) that defines the network protocol (or action to be takenby the user agent) when a request is made to a URL. For example, a request to aURL with an https scheme should be made using the HTTPS protocol. For a request to a URL with a schemesuch as file, mailto or git that doesn't correspond to a networkprotocol, behavior depends on the user agent. For example, when a user clickson a mailto link, most browsers open their default email application, usingthe values in the link's href URL.

Search

A question mark followed by a series of key-value pairs that representparameters and their values, provided after the pathname.

URL URL.search
https://example.com/cats?pattern=tabby&mood=bonkers ?pattern=tabby&mood=bonkers
https://example.com/cats:443?pattern=tabby ?pattern=tabby

The query or "query string" refers to the search without theleading ?.

See also Search params.

Search params

Refer to an item of data passed in a search string(or "query string").

  • For example: for https://example.com/cats?pattern=tabby&mood=bonkers, thesearch string has two parameters: pattern=tabby and mood=bonkers.

Second-level domain

The domain before a top-level domain.

  • For the URL https://www.example.com, the second-level domain isexample.com, a subdomain of the top-level domain com.

  • For https://example.org.au, the top-level domain is au, the second-leveldomain is org and the third-level domain is example. In this example,org.au is a subdomain of au and example.org.au is a subdomain oforg.au.

Site

Site is defined bythe HTML standard, along with same-site, whichincludes scheme, andschemeless same-site.

Site is not defined in the URL standard or the JavaScript URL API.

In this context:

  • For an HTTP or HTTPS URL with a single-part eTLD such ashttps://example.com, the site consists of the scheme, the eTLD and thelabel beforethat. For example: for the URL https://www.example.com/cat, the site ishttps://example.com. (For this URL, the eTLD is the same as thetop-level domain.)
  • For multipart eTLDs such as co.uk, github.io or sa.edu.au,the "site" consists of the scheme, the eTLD and the label before that.For example: for the URL https://cat.example.co.uk/tabby, the site ishttps://example.co.uk, and for https://www.education.sa.gov.au the siteis https://education.sa.gov.au.
URL Site (with scheme and eTLD +1)
https://cat.example.com/tabby ("https", "example.com")
https://cat.example.co.uk/tabby ("https", "example.co.uk")

Unlike origin, site does not include port.

Subdomain

A domain within a higher-level domain.

For sites with single-part top-level domains such as com or org, the partsbefore the top-level domain, each of which is separated by a dot.

  • www.example.com is a subdomain of example.com.
  • support.api.example.org is a subdomain of api.example.org, which is asubdomain of example.org.

For two-part eTLDs where only third-level registrations are allowed(i.e. entriesin the Public Suffix List such as co.uk andgithub.io) the subdomains are the parts of the domain name before that.

  • For example: cat.example.co.uk is a subdomain of example.co.uk.

Text fragment

A type of fragment that makes it possible to link to and highlighta range of text within a page. When a user follows a link with a text fragment,the browser attempts to locate, scroll to and highlight the text within the page.

A text fragment begins with :~:text= followed by the search term.

For example, to link to the first occurrence of the text "fragment"on this page, use the URL https://web.dev/articles/url-parts#:~:text=fragment.

Find out more: Text fragments.

Top-level domain (TLD)

A domain name listed in the Root Zone Database such as com or org. Some top-level domains arecountry code top-level domains, such as uk and tv.

When describing the parts of an HTTP or HTTPS URL, the TLD is the domain namethat follows the final dot.

  • For https://example.org, the URL's top-level domain is org.
  • For https://example.org.au, the URL's top-level domain is au, and orgis a second-level domain (even though org is also a top-leveldomain). org.au is a two-part eTLD.

The Public Suffix List of eTLDs includes domains with one, two or more parts, so a TLD can also be aneTLD. For example:

  • For https://example.com, the URL's eTLD is com, which is also a TLD.

Username

An optional username and password can be provided at the beginningof the URL, but this has been deprecatedfor security reasons and will be ignored in many cases.

For example, with https://user123:password1@example.com the username isuser123. Note the username (and password!) is in plain text and not encrypted.If the username contains : or @ symbols they must be URL encoded to %3Aand %40 respectively.

Find out more

What are the parts of a URL?  |  Articles  |  web.dev (2024)
Top Articles
Latest Posts
Article information

Author: Nicola Considine CPA

Last Updated:

Views: 6464

Rating: 4.9 / 5 (49 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Nicola Considine CPA

Birthday: 1993-02-26

Address: 3809 Clinton Inlet, East Aleisha, UT 46318-2392

Phone: +2681424145499

Job: Government Technician

Hobby: Calligraphy, Lego building, Worldbuilding, Shooting, Bird watching, Shopping, Cooking

Introduction: My name is Nicola Considine CPA, I am a determined, witty, powerful, brainy, open, smiling, proud person who loves writing and wants to share my knowledge and understanding with you.