The basic HTML link uses the anchor tag with an href attribute

A link in HTML is created with the <a> tag, short for "anchor". The tag wraps around the text you want to be clickable, and the href attribute tells the browser where to send the reader when they click. Here is the simplest form:

<a href="https://example.com">Click here</a>

When a browser displays this, the reader sees "Click here" as a blue underlined link. When they click it, the browser opens https://example.com. The text between the opening and closing tags — "Click here" in this example — is what appears on the page. The href value is the destination, which can be a full web address, a file path, or an anchor within the same page.

Key Takeaways

  • The <a> tag with an href attribute creates a clickable link; the text between the tags is what the reader sees.
  • Use a full web address like https://example.com to link to other websites, or a relative path like pages/about.html to link to files in your own site.
  • Add target="_blank" to the tag if you want the link to open in a new browser tab instead of replacing the current page.
  • Link text should describe where the link goes or what happens when clicked, not just say "click here".

Linking to other websites

When you want to link to a page on another website, use the full web address in the href attribute, starting with http:// or https://. The browser needs this to know it is leaving your site.

<a href="https://www.wikipedia.org">Learn more on Wikipedia</a>

Always use https:// when the website supports it. The "s" means the connection is encrypted, which protects the reader's data. Most modern websites use https by default, so if you are unsure, try https first.

Linking to pages within your own site

When linking to another page on your own website, you do not need the full web address. Instead, use a relative path — the file path from your current page to the page you want to link to.

If your site has this structure:

  • index.html (your home page)
  • pages/about.html
  • pages/contact.html

From index.html, you would link to the about page like this:

<a href="pages/about.html">About Us</a>

From the about page back to the home page, you would use:

<a href="../index.html">Home</a>

The ../ means "go up one folder level". This approach keeps your links working even if you move your entire site to a different web address, because the paths between your own files stay the same.

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 browser tab instead, add the target="_blank" attribute:

<a href="https://example.com" target="_blank">Open in new tab</a>

This is useful when linking to external sites, so the reader does not lose their place on your page. It is less useful for links within your own site, where you usually want the reader to navigate forward. Some developers also add rel="noopener noreferrer" to external links for security reasons, though modern browsers handle this automatically in most cases.

Linking to a specific section within a page

You can link directly to a heading or section within a page using an anchor — a named location on the page. First, add an id attribute to the heading or section you want to link to:

<h2 id="contact-section">Contact Us</h2>

Then link to it by adding a hash symbol and the id name to the href:

<a href="#contact-section">Jump to Contact</a>

If you want to link to a section on a different page, combine the file path with the anchor:

<a href="pages/about.html#team-section">See our team</a>

Writing link text that describes the destination

The text between the opening and closing <a> tags should tell the reader where the link goes or what happens when they click it. Avoid generic phrases like "click here" or "read more", because they do not work well for people using screen readers and do not help readers understand the link before they click.

Instead of: <a href="https://example.com">Click here</a>

Write: <a href="https://example.com">Learn about our pricing</a>

Descriptive link text also helps search engines understand what your pages are about, which can improve how your site appears in search results. When someone shares your page on social media or in a message, the link text is often what appears, so clear wording matters for both accessibility and user experience.

Frequently Asked Questions

Can I put an image inside an anchor tag to make it clickable?

Yes. Put an <img> tag inside the <a> tag: <a href="https://example.com"><img src="logo.png" alt="Company logo"></a>. The image becomes clickable and behaves like a text link. Always include an alt attribute on the image so screen readers can describe what it is.

What is the difference between href and src?

href is used in anchor tags to specify where a link goes. src is used in image tags to specify where the image file is located. They serve different purposes: href is for navigation, src is for embedding content.

How do I link to an email address?

Use mailto: in the href: <a href="mailto:contact@example.com">Email us</a>. When a reader clicks this link, their default email program opens with the address already filled in. You can also add a subject line: <a href="mailto:contact@example.com?subject=Question">Email us</a>.

Do I need to add anything to make a link work on mobile phones?

No. Standard HTML links work the same way on mobile as on desktop. The browser handles the click automatically. If you want to make links easier to tap on a small screen, use CSS to make them larger or add more space around them, but the HTML itself does not change.