• Skip to main content
  • Skip to search
  • Skip to select language
    • Technologies Overview
    • HTML
    • CSS
    • JavaScript
    • Graphics
    • HTTP
    • APIs
    • Browser Extensions
    • MathML
    • Learn web development
    • Tutorials
    • References
    • Developer Guides
    • Accessibility
    • Game development
    • ...more docs
    • Send Feedback
    • Contribute to MDN
    • Report a content issue 🌐
    • Report a platform issue 🌐
  1. Web technology for developers
  2. Web APIs
  3. Location
  4. Location: hostname
  • Change language

Table of contents

  • Syntax
  • Examples
  • Specifications
  • Browser compatibility

Location: hostname

The hostname property of the Location interface is a USVString containing the domain of the URL.

Syntax

string = object.hostname;
object.hostname = string;

Examples

var anchor = document.createElement("a");
anchor.href = "https://developer.mozilla.org:4097/en-US/docs/Location.hostname";

console.log(anchor.hostname);  // developer.mozilla.org

Specifications

Specification
HTML Standard
# dom-location-hostname-dev

Browser compatibility

BCD tables only load in the browser

Found a problem with this page?

  • Edit on GitHub
  • Source on GitHub
  • Report a problem with this content on GitHub
  • Want to fix the problem yourself? See our Contribution guide.

Last modified: Jan 4, 2022, by MDN contributors

Change your language

Related Topics

  1. URL API
  2. Location
  3. Properties
    1. Location: ancestorOrigins
    2. Location: hash
    3. Location: host
    4. Location: hostname
    5. Location: href
    6. Location: origin
    7. Location: password
    8. Location: pathname
    9. Location: port
    10. Location: protocol
    11. Location: search
    12. Location: username
  4. Methods
    1. Location: assign()
    2. Location: reload()
    3. Location: replace()
    4. Location: toString()
  5. Related pages for URL API
    1. URL
    2. URLSearchParams
  • Web Technologies
  • Learn Web Development
  • About MDN
  • Feedback
  • About
  • MDN Web Docs Store
  • Contact Us
  • Firefox

MDN

  • MDN on Twitter
  • MDN on Github

Mozilla

  • Mozilla on Twitter
  • Mozilla on Instagram

© 2005-2022 Mozilla and individual contributors. Content is available under these licenses.

  • Terms
  • Privacy
  • Cookies