The basic HTML tag for links

To make a URL clickable, wrap it in an anchor tag — the HTML element that turns text into a link. The tag looks like this: <a href="https://example.com">Click here</a>. The href attribute holds the URL, and the text between the opening and closing tags is what appears on the page.

When a visitor clicks that text, their browser goes to the URL you specified. The text you choose to display does not have to match the URL itself — you can write "Learn more about our pricing" as the link text even if the href points to yoursite.com/plans.

Key Takeaways

  • An anchor tag with an href attribute is the only way to make a URL clickable in HTML: <a href="URL">text</a>.
  • Always include the full protocol (https:// or http://) when linking to external websites, or the browser will treat it as a relative link.
  • You can link to pages within your own site using relative paths like href="/about" or href="pages/contact.html" without typing the full domain.
  • Add target="_blank" to the anchor tag if you want the link to open in a new tab instead of replacing the current page.

External links versus internal links

When linking to a website outside your own, always include the full URL starting with https:// or http://. Without it, the browser assumes you mean a page on your own site. So <a href="https://google.com">Google</a> works, but <a href="google.com">Google</a> will look for a file called google.com on your server and fail.

For links within your own site, you can use relative paths instead of the full URL. If you have a page at yoursite.com/about, you can link to it from another page using just <a href="/about">About Us</a>. The forward slash at the start means "from the root of this site." You can also use href="about.html" to link to a file in the same folder, or href="../contact.html" to go up one folder level.

Opening links in a new tab

By default, clicking a link replaces the current page with the destination. If you want the link to open in a new tab instead, add the target="_blank" attribute: <a href="https://example.com" target="_blank">Visit Example</a>.

This is useful when linking to external sites so visitors do not leave your page. However, use it sparingly — most visitors expect links to behave normally, and opening new tabs without warning can feel intrusive. A common practice is to use target="_blank" only for external links, not for links within your own site.

Styling links with CSS

By default, links appear in blue and underlined. You can change their appearance using CSS. The most common approach is to target the <a> tag in your stylesheet: a { color: red; text-decoration: none; } removes the underline and makes all links red.

You can also style links differently depending on their state. The :hover pseudo-class applies styles when a visitor hovers their mouse over the link, and :visited applies styles to links the visitor has already clicked. For example, a:hover { color: orange; } makes links turn orange when you hover over them. This feedback helps visitors understand that something is clickable.

Linking to specific sections within a page

You can link directly to a specific section of a page using an anchor — a named location within the HTML. First, add an id attribute to the element you want to link to: <h2 id="pricing">Our Pricing</h2>. Then link to it using a hash symbol: <a href="#pricing">Jump to Pricing</a>.

This works across pages too. If you want to link to the pricing section on a different page, use <a href="/plans#pricing">See Our Pricing</a>. When someone clicks that link, the browser navigates to the page and automatically scrolls to the element with id="pricing". This is especially useful for long pages with a table of contents.

Common mistakes to avoid

Forgetting the protocol is the most frequent error — href="example.com" will not work as an external link. Always include https:// at the start. Another common mistake is using spaces or special characters in relative paths without escaping them, which breaks the link.

Avoid using generic link text like "Click here" or "Read more." Instead, write descriptive text that tells visitors where the link goes: "Learn about our refund policy" is better than "Click here." This helps both visitors and search engines understand what the link is for. Also check that your links actually point where you think they do — typos in URLs are easy to miss and will frustrate visitors.

Frequently Asked Questions

What is the difference between href and src?

href is used in anchor tags to link to other pages or resources. src is used in image and script tags to load a file directly into the page. You use href to create clickable links; you use src to embed images or code.

Can I link to a PDF or other file types?

Yes. Use the full path to the file in the href: <a href="/documents/guide.pdf">Download Guide</a>. When someone clicks it, their browser will either open the file or prompt them to download it, depending on their browser settings and the file type.

How do I link to an email address?

Use href="mailto:email@example.com". When clicked, it opens the visitor's default email client with that address in the "to" field. You can also add a subject line: href="mailto:email@example.com?subject=Hello".

Why does my link not work?

Check three things: the URL is spelled correctly, external links include the full protocol (https://), and the closing tag is present. Use your browser's developer tools to inspect the link and see what URL it actually points to — right-click the link, select "Inspect," and look at the href value in the HTML.