Every computer or service on a network can carry a name, so people can reach it with words instead of an IP address. That name is its hostname. On the web, it's the part of a URL between https:// and the next slash or colon. In https://www.example.com:8443/pricing, the hostname is www.example.com.
In JavaScript, a URL's hostname property gives you exactly that part. Its sibling host adds the port when there is one: www.example.com:8443.
Two meanings of "hostname"
The word is used in two ways, and the DNS standards never formally defined it. RFC 9499
- The full name, such as
www.example.comormail.example.org. This is the meaning in URLs, browsers, web servers and analytics. - Just a machine's own name, the first label, such as
printerinprinter.admin.example.com. This is the meaning when someone asks for "your computer's hostname".
The full name, with every label up to the top-level domain, is also called a fully qualified domain name (FQDN). Strictly, an FQDN ends with a dot for the DNS root, as in www.example.com., but people usually leave it off.
Hostname, domain and subdomain
A hostname can be the same as your registered domain, or a subdomain of it:
| URL | Hostname | Registered domain | Subdomain part |
|---|---|---|---|
https://example.com/ |
example.com |
example.com |
none |
https://www.example.com/ |
www.example.com |
example.com |
www |
https://blog.example.co.uk/ |
blog.example.co.uk |
example.co.uk |
blog |
The domain name is what you register and renew. Hostnames are the names you create under it, each pointing somewhere through DNS.
Rules for a valid hostname
Hostnames follow the DNS "preferred name syntax", with one later change:
- Characters. Each label, the part between dots, uses only letters a to z, digits 0 to 9 and hyphens. It can start with a letter or a digit and must end with a letter or a digit. Underscores aren't part of the syntax, so keep them out of names people browse to.
- Length. Each label can be up to 63 characters. The whole name can be at most 255 octets as DNS stores it, counting a length byte for each label, which leaves 253 characters when you write it out.
- Case. Hostnames are case-insensitive:
Example.COMandexample.comare the same host. - Other alphabets. Names in other scripts are converted to an ASCII form starting with
xn--. A browser turns你好.comintoxn--6qq79v.com.
Why hostnames matter for SEO
To a search engine, https://example.com/ and https://www.example.com/ are two different URLs that may show the same page. Google's advice is to pick one version as your canonical URL and redirect the others to it. Google Search Central Read more under canonical tag.
Hostnames also decide what your tools count:
- Google Search Console. A Domain property covers every hostname under your domain, www and non-www, on all protocols. A URL-prefix property covers only the exact prefix you enter, such as
https://www.example.com/. - Google Analytics 4. The Hostname dimension shows which hostname each visit happened on. Filter by it to spot your tracking code firing on a staging copy or on someone else's site.
How to find a computer's hostname
- Windows. Open Command Prompt and type
hostname. It shows the host name part of the computer's full name. - Linux. Type
hostnamein a terminal. Add-fto see the fully qualified name. - A website. The hostname is in the address bar, between
https://and the first slash.