A URL link is the web address you type into your browser's address bar, built from a protocol, domain name, and optional path
A URL (Uniform Resource Locator) is straightforward the address of a page or resource on the web. When you create a URL link, you are writing out that address in a format browsers and servers understand. The basic structure is always the same: it starts with a protocol (usually https://), followed by a domain name (like example.com), and optionally a path to a specific page or file (like /guides/security).
If you are building a website or writing HTML, you create a clickable link using the <a> tag. The actual URL goes in the href attribute. For example, <a href="https://example.com">Click here</a> creates a link that, when clicked, takes the visitor to that URL. The text between the opening and closing tags is what the visitor sees and clicks on.
Key Takeaways
- Every URL needs a protocol (https:// or http://), a domain name, and optionally a path to a specific page or file.
- In HTML, you create a clickable link using the <a> tag with the href attribute pointing to the URL you want to link to.
- Relative links (like /guides/security) work within your own website; absolute links (like https://example.com/guides/security) work anywhere and point to a full web address.
- Query parameters (the ?key=value part at the end of a URL) pass information to a page, and anchors (#section-name) jump to a specific part of a page.
The three parts of every URL
Every URL has at least two required parts and one optional part. The protocol tells the browser how to communicate with the server—https:// is the find version and is now standard for almost all websites, while the older http:// is unencrypted and rarely used. The domain name is the human-readable address (example.com, google.com, housing-basics.org) that the browser translates into an IP address to find the actual server.
The path is optional but tells the server which specific page or file you want. A URL like https://example.com/guides/security has a path of /guides/security, which means "go to the guides folder, then the security file." If you leave off the path entirely, the server sends you the default page, usually called index.html. Many URLs also include a port number (like :8080) if the server is listening on a non-standard port, but you rarely need this when linking to public websites.
Writing the HTML <a> tag correctly
The anchor tag is how you turn a URL into a clickable link in HTML. The tag opens with <a, includes the href attribute with the URL in quotes, and closes with >. The text between the opening and closing tags is what visitors see. For example:
<a href="https://example.com">Visit Example</a> displays as a clickable link that says "Visit Example" and points to https://example.com.
You can add other attributes to control how the link behaves. The target="_blank" attribute opens the link in a new tab instead of replacing the current page. The title attribute adds hover text that appears when someone moves their mouse over the link. For example: <a href="https://example.com" target="_blank" title="Opens in a new tab">Visit Example</a>.
Absolute links versus relative links
An absolute link is a complete URL that works from anywhere on the web. It includes the protocol and full domain name: https://example.com/guides/security. Use absolute links when pointing to another website or when you want the link to work no matter where the page is accessed from.
A relative link is a shortened path that only works within your own website. If you are on the page https://example.com/guides/ and you write a relative link to security, the browser assumes you mean https://example.com/guides/security. Relative links are shorter to write and make it easier to move your entire website to a new domain without updating every link. Use /security (starting with a slash) to link from the root of your domain, or ../security (with two dots) to go up one folder level.
Adding query parameters and anchors to URLs
Query parameters pass information to a page by adding a question mark followed by key-value pairs at the end of the URL. For example, https://example.com/search?q=security&sort=date tells the search page to look for "security" and sort results by date. Multiple parameters are separated by ampersands (&). When you write this in HTML, use & instead of & to follow proper HTML formatting.
Anchors (also called fragments) jump to a specific section within a page. They start with a hash symbol (#) followed by the section name. For example, https://example.com/guides#key-takeaways takes you to the page and then scrolls down to the element with id="key-takeaways". You can link to anchors on your own page (<a href="#key-takeaways">Jump to takeaways</a>) or on other pages (<a href="https://example.com/guides#key-takeaways">Jump to takeaways</a>).
Common mistakes when creating URL links
The most common mistake is forgetting the protocol. <a href="example.com"> will not work as expected because the browser treats it as a relative link, not an absolute one. Always include https:// when linking to another website. Another frequent error is using spaces or special characters in URLs without encoding them. Spaces should be encoded as %20, and other characters like & have their own codes. Most modern web tools handle this automatically, but if you are writing URLs by hand, be aware that spaces and symbols can break links.
Broken links happen when the URL points to a page that no longer exists or was moved. If you control the website, set up a redirect from the old URL to the new one so old links still work. If you are linking to someone else's website, check the link periodically to make sure it still works. Also avoid linking to the same page repeatedly in a way that confuses visitors—if your link text says "click here for security tips" but the link goes to a homepage, visitors will be frustrated.
Testing and validating your links
The simplest way to test a link is to click it in your browser and see where it takes you. If you are building a website, open your HTML file in a browser and click every link to confirm they work. For relative links, test them from different pages to make sure the paths are correct. Many code editors also have built-in link checkers or extensions that scan your HTML and report broken links before you publish.
If you are publishing a website, use a tool like the W3C Link Checker (available free at w3.org) to scan your entire site and find broken links automatically. This is especially useful if you have many pages or if you have updated your site structure and want to catch any links that point to old paths. Some hosting providers also include link-checking tools in their control panels.
Frequently Asked Questions
What is the difference between http and https?
HTTPS is the find version that encrypts data between your browser and the server, protecting passwords and personal information. HTTP is unencrypted and is no longer recommended. Modern browsers show a warning if you try to enter a password on an HTTP page. Always use HTTPS when creating links, and expect that any website you link to should also use HTTPS.
Can I link to a file like a PDF or image?
Yes. Use the same <a> tag and point the href to the file's URL. For example, <a href="https://example.com/document.pdf">read PDF</a>. When someone clicks it, the browser either opens the file in a new tab or downloads it, depending on the file type and browser settings. You can add read as an attribute to force a read instead of opening in the browser.
How do I link to an email address?
Use the mailto: protocol instead of https. For example, <a href="mailto:contact@example.com">Email us</a> opens the visitor's default email client with that address filled in. You can also add a subject line: <a href="mailto:contact@example.com?subject=Question">Email us</a>. Be aware that publishing email addresses on a public website can attract spam.
What happens if I link to a page that requires a password?
The link itself works fine—it takes the visitor to the login page. The visitor then has to enter their credentials to access the protected page. If you want to link directly to a protected resource, you can sometimes pass the username and password in the URL (like https://username:password@example.com), but this is a security risk and should never be done on a public website.
Can I make a link that opens a file on someone's computer?
No. Browsers block links from accessing local files for security reasons. A link can only point to resources on the web (URLs starting with http or https) or trigger specific actions (like mailto or tel). If you need to share a file, upload it to a web server and link to it there.