Quick answerTo add a link in HTML, wrap the clickable text in an anchor tag: <a href="https://example.com">Visit Example</a>. The href attribute is the address the link goes to: a full URL for another website, a file name like about.html for another page on your site, or #id for a section of the same page.
The HTML link code
Every HTML link uses the same tag, <a> (short for anchor). The text between the opening and closing tag is what people click, and href is where it goes:
<a href="https://www.example.com/">Visit Example</a>
| Part | What it does |
|---|---|
<a> | Starts the link. Links are inline, so they can sit in the middle of a sentence. |
href="…" | The destination: a URL, a file name, a #section, mailto: or tel:. |
| Link text | The visible, clickable words. Screen readers and search engines use it to understand the link. |
</a> | Ends the link. Without it, everything after the link becomes part of it. |
How to link to another page in HTML
To link HTML pages on your own site, put the other file's name in href. Here a home page links to an about page in the same folder, and the about page links back:
my-site/
├── index.html
└── about.html
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Home</title>
</head>
<body>
<h1>Welcome to my site</h1>
<p>Read <a href="about.html">about us</a> or visit
<a href="https://developer.mozilla.org/">MDN Web Docs</a>.</p>
</body>
</html>
about.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>About us</title>
</head>
<body>
<h1>About us</h1>
<p>You followed a link from index.html to about.html.</p>
<p><a href="index.html">Back to the home page</a></p>
</body>
</html>

This is a relative link: the browser finds about.html starting from the folder the current page is in. When the pages are in different folders, change the path:
| Where the other page is | href to use |
|---|---|
| Same folder | about.html |
| In a sub-folder | blog/post.html |
| One folder up | ../index.html |
| From the site root (on a web server) | /contact.html |
Paths work exactly the same way for stylesheets and scripts. The CSS linking guide has more folder examples.
How to add an external link in HTML
To link to another website, use the full address, including https://:
<a href="https://developer.mozilla.org/">MDN Web Docs</a>
Without https://, the browser treats developer.mozilla.org as a file in your own folder and the link breaks. Copy the address from the browser's address bar to be safe.
Open a link in a new tab
Add target="_blank". Modern browsers also apply rel="noopener" automatically, but writing it keeps older browsers safe too:
<a href="https://www.w3.org/" target="_blank" rel="noopener">W3C</a>
Use it sparingly, for example for a PDF or an external tool while someone fills in a form. People expect normal links to open in the same tab, and they can always open a new tab themselves.
Link to a section of the same page
Give the target element an id, then link to it with # and the same name. This is how tables of contents and "back to top" links work:
<a href="#contact">Jump to contact</a>
…
<h2 id="contact">Contact</h2>
To jump to a section on another page, combine both: <a href="about.html#team">.
Email and phone links
<a href="mailto:hello@example.com">hello@example.com</a>
<a href="mailto:hello@example.com?subject=Question">Email us</a>
<a href="tel:+15551234567">+1 555 123 4567</a>
mailto: opens the visitor's email app and tel: starts a call on a phone. Write phone numbers in international format (+, country code, no spaces) inside href.
Make an image or a button a link
Put the image inside the link. The image's alt text becomes the link's name, so describe where it goes:
<a href="/"><img src="logo.png" alt="HTML Online home page"></a>
For a button that goes to another page, use a link and style it with CSS, rather than a <button> with JavaScript. It works without JavaScript, can be opened in a new tab, and screen readers announce it correctly:
<a class="button" href="signup.html">Sign up</a>
Download links
The download attribute asks the browser to save the file instead of opening it, and can suggest a file name:
<a href="files/report.pdf" download="report-2026.pdf">Download the report (PDF)</a>
It only works for files on the same website. For files on other sites, the browser decides whether to open or save them.
Every kind of link in one example
This page uses section links, external links, a new-tab link, email and phone links, a button-style link and a download link:
Open this example in the editor →

Write link text that works for people and search engines
- Say where the link goes. "Read our HTML boilerplate guide" beats "click here". Screen reader users often jump from link to link, hearing only the link text.
- Keep it short: a few words, not a whole sentence.
- Warn about surprises: say "(PDF)", "(opens in a new tab)" or "(download)" when that's what happens.
- Use the right
relfor paid or user links. Search engines ask forrel="sponsored"on paid links,rel="ugc"on links in comments or forum posts, andrel="nofollow"when you don't want to vouch for a site.
From the authorWhen I review client sites, the two link mistakes I see most are external links written without https:// (so they point to a page that doesn't exist on the client's own site) and a missing </a> that turns a whole paragraph into one big link. Both take seconds to spot in the HTML validator. — Faisal Nadeem
Link not working? Check these 8 things
- Missing
https://on an external link. The browser looks for a file with that name on your own site instead. - Wrong file name or folder. Check the spelling, the folder and the
.htmlending. On most web serversAbout.htmlandabout.htmlare different files. - A missing
</a>. Everything after the link becomes clickable. Close every link. - A link inside another link. Browsers don't allow nested
<a>tags and will split them in unexpected ways. - Spaces in file names.
my page.htmlworks locally but is fragile online. Use hyphens:my-page.html. - A leading slash on a local file.
href="/about.html"means the root of your hard drive when you open the file directly from your computer (file://). Usehref="about.html"until the site is on a server. - The
#iddoesn't match.href="#Contact"won't findid="contact": ids are case-sensitive. - Something covers the link. If the cursor doesn't change to a hand, another element (often a transparent one with
position: absolute) is on top. Right-click → Inspect to find it.
Run your page through the HTML validator to catch unclosed and nested tags with line numbers.
More HTML linking guides
- How to link CSS to HTML: connect a stylesheet with
<link>. - How to link JavaScript to HTML: load a script with
<script src>. - HTML cheat sheet: every common tag with an example.
- How to make a website with HTML and CSS: put links, pages and styles together into a real site.
Frequently asked questions
How do I add a link in HTML?
Use the anchor tag: <a href="https://example.com">link text</a>. Put the destination in href and the clickable words between the tags.
How do I link to another page on my website?
Put the page's file name or path in href, for example <a href="about.html">About</a> for a page in the same folder, or blog/post.html for a page in a sub-folder.
How do I add an external link in HTML?
Use the full web address including https://, for example <a href="https://developer.mozilla.org/">MDN</a>. Without https:// the browser treats the address as a file on your own site.
How do I make a link open in a new tab?
Add target="_blank" rel="noopener" to the a tag. Use it only when there's a good reason, because people expect links to open in the same tab.
Can I make an image a link?
Yes. Put the <img> inside the <a> tag and give the image alt text that describes where the link goes.
Why is my HTML link not working?
Check for a missing https:// on external links, a misspelled file name or folder, a missing </a>, and ids that don't match exactly. The HTML validator finds unclosed tags quickly.