What a URL link is and why you need one

A URL link is the web address you type into a browser's address bar — the thing that starts with http:// or https://. When you create a URL link, you are making a clickable address that points to a specific page, file, or resource on the internet. Most of the time, you are not actually creating the URL itself; instead, you are creating the HTML code that makes that URL clickable in a web page or document.

The difference matters. The URL already exists once a page is published on the web. What you are doing is writing the code that turns it into a link someone can click. That code is called an anchor tag, and it looks like this: <a href="https://example.com">Click here</a>. The part in quotes is the URL. The part between the tags is the text that appears clickable to the reader.

Key Takeaways

  • A clickable link in HTML uses an anchor tag with the format <a href="URL">link text</a>, where the URL goes in the quotes and the visible text goes between the tags.
  • URLs must include the protocol (http:// or https://) to work correctly; https:// is the secure version and is now standard for most websites.
  • Relative links point to pages within your own website and use shorter paths like href="about.html", while absolute links use the full web address.
  • You can link to files, email addresses, and phone numbers by changing what goes inside the href attribute — each type has its own format.
  • Test every link you create by clicking it to make sure it goes where you intended and that the page loads correctly.

The basic HTML anchor tag structure

Every clickable link on a web page starts with the same basic structure. Open with <a, add the href attribute with your URL in quotes, close with >, then type the text you want readers to see, then close with </a>.

Here is a real example: <a href="https://www.wikipedia.org">Visit Wikipedia</a>. When a browser displays this code, the reader sees only the words "Visit Wikipedia" in blue and underlined. When they click it, the browser goes to wikipedia.org.

The text between the opening and closing tags — the part the reader actually sees and clicks — can be anything. It can be a single word, a full sentence, or even an image. The URL in the href attribute is what matters for where the link goes. Many people make the mistake of putting the URL in the visible text instead of in the href attribute, which creates a link that displays the URL but does not work as a clickable link.

Using absolute URLs versus relative URLs

An absolute URL is the complete web address, starting with http:// or https://. Use absolute URLs when you are linking to pages outside your own website, or when you want the link to work the same way no matter where it is placed. Example: <a href="https://www.google.com">Search Google</a>.

A relative URL is a shorter path that works only within your own website. If you have a file called about.html in the same folder as your current page, you can link to it with just <a href="about.html">About Us</a>. If about.html is in a subfolder called pages, use <a href="pages/about.html">About Us</a>. Relative links are shorter to type and keep working if you move your entire website to a different server.

Most websites use a mix of both. Links to external sites use absolute URLs. Links between pages within the same site use relative URLs. If you are not sure which one to use, absolute URLs always work, so start there.

Creating links to email addresses and phone numbers

You can create a link that opens the reader's email program or phone dialer by using special URL formats. For email, use <a href="mailto:name@example.com">Email us</a>. When someone clicks this link, their default email program opens with a new message addressed to that email.

For phone numbers, use <a href="tel:+1-555-123-4567">Call us</a>. The plus sign and hyphens are optional, but including them makes the number easier to read in your code. On a mobile device, clicking this link dials the number. On a desktop, it may do nothing or open a calling program if one is installed.

You can also add a subject line to email links: <a href="mailto:name@example.com?subject=Question">Email us</a>. The question mark separates the email address from the subject parameter. If you want to add a message body as well, use <a href="mailto:name@example.com?subject=Question&body=Hello">Email us</a>. Notice the ampersand (&) between parameters.

Making sure your links actually work

After you write a link, test it immediately by clicking it in your browser. The most common mistake is a typo in the URL — a missing letter, a wrong slash, or a forgotten .com. If the link does not go where you expected, check the href attribute character by character.

Another common problem is forgetting the protocol. <a href="example.com"> will not work the way you expect; the browser will treat it as a relative link and look for a file called example.com in your current folder. Always include http:// or https://. Modern browsers usually default to https://, which is the secure version, so use that unless you have a specific reason not to.

If you are linking to a file on your own website and the link does not work, check that the file path is correct. If your HTML file is in the root folder and your image is in a subfolder called images, the correct relative link is href="images/photo.jpg", not href="/images/photo.jpg" (the leading slash changes the meaning). Test the path by navigating to that file manually in your browser first, then copy the path from the address bar.

Adding titles and styling to links

You can add a title attribute to a link to show a tooltip when someone hovers over it. This is useful for clarifying where the link goes or providing extra context. The code looks like this: <a href="https://example.com" title="Learn more about our company">Our company</a>. When a reader moves their mouse over "Our company", a small box appears with the text "Learn more about our company".

You can also add a target attribute to control whether the link opens in the same window or a new one. <a href="https://example.com" target="_blank">Visit example</a> opens the link in a new tab or window. Use this sparingly — most readers prefer to control whether a link opens in a new window themselves. It is useful for external links you want to keep readers on your site while they explore.

To style a link with color or other formatting, use CSS. In your style sheet, you can change the color of all links, remove the underline, or change the color when someone hovers over it. This is beyond the scope of the HTML link itself, but it is worth knowing that the link code and the styling are separate — the HTML creates the link, and CSS changes how it looks.

Common mistakes and how to fix them

Forgetting the closing tag is one of the most common errors. If you write <a href="https://example.com">Click here without the </a>, everything after that link will be underlined and clickable, which is not what you want. Always close every anchor tag.

Putting the URL in the wrong place is another frequent mistake. The URL must go inside the href attribute in quotes, not in the visible text. Wrong: <a>https://example.com</a>. Right: <a href="https://example.com">Click here</a>.

Using spaces or special characters in file names can break relative links. If you have a file called "my page.html" with a space in the name, the link will not work. Use hyphens or underscores instead: "my-page.html" or "my_page.html". If you inherit a website with spaces in file names, replace them before linking.

Frequently Asked Questions

Do I need to include http:// or https:// in the URL?

Yes. Without the protocol, the browser treats the URL as a relative link and looks for a file in your current folder instead of going to the web. Always include https:// (the secure version) unless you have a specific reason to use http://.

What is the difference between target="_blank" and target="_self"?

target="_blank" opens the link in a new tab or window. target="_self" opens it in the same tab (this is the default behavior, so you do not need to write it). Use _blank sparingly — most readers prefer to control whether links open in new windows.

Can I link to a PDF or a Word document?

Yes. Use the same anchor tag format with the file path in the href: <a href="documents/report.pdf">Download report</a>. When someone clicks it, the browser will either open the file or prompt them to download it, depending on their browser settings.

Why does my link work on my computer but not when I upload it to the web?

This usually means you used an absolute path to a file on your computer instead of a relative path. Absolute paths like C:\Users\YourName\Documents\file.html do not work on the web. Use relative paths instead: href="file.html" or href="folder/file.html".

Can I make an image clickable?

Yes. Put an image tag inside the anchor tag: <a href="https://example.com"><img src="image.jpg"></a>. When someone clicks the image, they go to the URL in the href attribute. This is useful for logo links and image galleries.