HOW-TO

How to add a link in HTML (and keep it working after you share the page)

The a tag, the kinds of href you can write, opening links in a new tab, linking to a section, and why links between your own pages break when you send the file to someone.

4 min read·

A link in HTML is an <a> tag with an href attribute. The text between the opening and closing tag is what people click; href is where it goes. Most broken links come down to how href is written.

Add the a tag

Put this inside <body> where the link should appear:

<a href="https://example.com">Visit our site</a>

Unlike <img>, the <a> tag needs a closing </a>. Anything inside it becomes clickable, including an image: <a href="https://example.com"><img src="logo.png" alt="Home"></a>. Save the file and reload the page in the browser.

Pick the right kind of href

  • ✓Another website: the full address with https://, such as href="https://example.com/pricing". Leave out https:// and the browser treats it as a file next to your page.
  • ✓Another page of your own in the same folder: href="about.html".
  • ✓A page in a subfolder: href="docs/setup.html". One folder up: href="../index.html".
  • ✓An email address: href="mailto:hello@example.com". It opens the visitor's email app.
  • ✓A phone number: href="tel:+15551234567". It starts a call on phones.
  • ✓A file to download: href="price-list.pdf" download. The download attribute asks the browser to save it instead of opening it.

Link to a section on the same page

Give the target an id, then link to it with a # and that id:

<h2 id="pricing">Pricing</h2>

<a href="#pricing">Jump to pricing</a>

The id must match exactly, including case, and appear only once on the page. To link to that section from another page, add the id after the file name: href="index.html#pricing".

Open a link in a new tab

Add target="_blank" and rel="noopener":

<a href="https://example.com" target="_blank" rel="noopener">Example</a>

rel="noopener" stops the new page from controlling the tab your page is in. Use new tabs for links that leave your site; links between your own pages usually read better in the same tab.

When a link does not work

  • ✓Clicking does nothing, or the rest of the page turned into a link: a missing </a> or a missing closing quote in href.
  • ✓You land on a "file not found" page with your own folder in the address: an external link written without https://.
  • ✓Works on your laptop, 404 online: the file name or case does not match. About.html and about.html are different files on most web servers.
  • ✓A path from your own disk, such as file:///C:/Users/... or /Users/..., works on your computer and nowhere else. Use a relative path.
  • ✓A # link scrolls nowhere: the id is misspelled or missing on the target.

Before you share the page

Links to other websites keep working wherever the page goes. Links to your own pages, such as href="about.html", only work if about.html travels with it in the same folder layout. Send one .html file by email or chat and those links lead nowhere.

Either change them to full https:// addresses of pages that are already online, or host the pages together and send one link. For a small site, see building a multi-page site without a build step.

Share it as a link

With FileShare Pro you upload the .html file from the dashboard, copy the link and send it. It opens as a page in any browser, on phones too, and the person opening it needs no account. If you fix a link later, upload the new version to the same link instead of sending a new file. Sign up free to share your first page.

Frequently asked

How do I add a link in HTML?

Use <a href="https://example.com">link text</a> inside <body>. href is where the link goes and the text between the tags is what people click.

How do I make a link open in a new tab?

Add target="_blank" rel="noopener" to the a tag. rel="noopener" stops the new page from controlling your page's tab.

How do I link to another page of my own site?

Use a relative path from the current file, such as href="about.html" for a file in the same folder or href="docs/setup.html" for one in a subfolder. Both files have to be online together for the link to work.

Why does my HTML link go to a file not found page?

Usually an external link is missing https://, so the browser looks for a file next to your page, or a file name or its case does not match. Check the address the browser lands on.

Got a page to share?

Drop the file, copy the link — live in seconds, free plan included.

Start sharing free