The simplest way to link HTML pages together
To link one HTML page to another, use the anchor tag — written as <a> — with an href attribute that points to the file you want to open. The text between the opening and closing tags is what the reader sees and clicks on.
Here is the actual code: <a href="about.html">Go to About</a>. When someone clicks "Go to About", their browser opens the file named about.html. That file must exist in the same folder as the page they are currently on, or you need to tell the browser where to find it.
The browser turns this into a clickable link, usually blue and underlined by default. You can change how it looks with CSS, but the HTML itself does the work of connecting the pages.
Key Takeaways
- Use the anchor tag <a href="filename.html">Link text</a> to create a clickable link between pages.
- The href attribute tells the browser which file to open when someone clicks the link.
- If the linked file is in a different folder, use a path like href="pages/about.html" or href="../index.html" to point to it.
- You can link to external websites by using the full web address: href="https://example.com".
- Links to files in the same folder need only the filename; links to files elsewhere need a path that shows the browser where to look.
Linking pages in the same folder
When both HTML files sit in the same folder on your computer or server, the link is straightforward. Write the filename exactly as it appears, including the .html extension.
If your folder contains index.html, about.html, and contact.html, a link from index.html to about.html looks like this:
<a href="about.html">Learn more about us</a>
The browser reads this and looks for about.html in the same location as the current page. Capitalization matters — if your file is named About.html with a capital A, you must write href="About.html" or the link will break on some servers.
Linking pages in different folders
When files are organized into subfolders, you need to tell the browser the path to follow. Think of it like giving directions: start from where you are, then describe which folders to enter.
If your structure looks like this — a main folder containing index.html, plus a subfolder called pages that contains about.html — the link from index.html to about.html is:
<a href="pages/about.html">About us</a>
The forward slash means "go into this folder." If you need to go up one level and then into a different folder, use two dots: href="../contact.html" means "go up one folder, then open contact.html." Two dots always mean "go up one level" in web paths.
Linking to external websites
To link to a website outside your own site, use the full web address starting with https:// or http://. Without this, the browser thinks you are linking to a file on your own server.
For example: <a href="https://www.example.com">Visit Example</a>. The browser recognizes the https:// and knows to go to the internet instead of looking for a local file.
You can also add target="_blank" to make the link open in a new tab: <a href="https://www.example.com" target="_blank">Visit Example</a>. This keeps your own site open in the original tab while the external site opens in a new one.
Linking to a specific section within a page
You can link directly to a heading or section on another page by using an anchor ID. First, add an id attribute to the heading you want to link to:
<h2 id="pricing">Our Pricing</h2>
Then link to it by adding a hash symbol and the ID name to the href:
<a href="about.html#pricing">See our pricing</a>
When someone clicks this link, the browser opens about.html and scrolls directly to the section with id="pricing". You can also link to a section on the same page by using just the hash: <a href="#pricing">Jump to pricing</a>.
Common mistakes that break links
The most frequent problem is a mismatch between the filename in your href and the actual filename on disk. If you write href="about.html" but the file is actually named About.html, the link breaks on most web servers because they treat uppercase and lowercase as different.
Another common error is forgetting the file extension. Writing href="about" instead of href="about.html" will not work. The browser needs to know it is looking for an HTML file.
Incorrect paths also break links. If you write href="pages/about.html" but the file is actually in a folder called content, the link fails. Double-check your folder structure and make sure the path matches exactly.
Finally, using backslashes instead of forward slashes breaks links on web servers. Always use forward slashes: href="pages/about.html", never href="pages\about.html".
Testing links on your computer before uploading
Before you upload your site to a web server, test all your links locally by opening the HTML file in your browser. Right-click the file, select "Open with," and choose your browser. Click each link to make sure it goes where you expect.
Links that work on your computer may still break after you upload if your folder structure changes or if you use the wrong path format. When you upload, keep the same folder organization you used locally, and your links should continue to work.
If a link works locally but breaks after uploading, the most likely cause is a path error or a filename mismatch. Check that the file exists on the server in the location your href points to, and verify that capitalization matches exactly.
Frequently Asked Questions
What is the difference between href and other HTML attributes?
The href attribute is specific to the anchor tag and tells the browser where to go when the link is clicked. Other tags have different attributes for different purposes — for example, the img tag uses src to point to an image file. Each attribute does a specific job.
Can I link to a PDF or other file types besides HTML?
Yes. Use the same anchor tag and point to the file: <a href="document.pdf">Download PDF</a>. The browser will either open the file or prompt the user to download it, depending on their settings and the file type.
How do I make a link open in a new tab instead of replacing the current page?
Add target="_blank" to the anchor tag: <a href="about.html" target="_blank">About us</a>. This tells the browser to open the link in a new tab while keeping the original page open.
What does the hash symbol do in a link?
The hash symbol (#) followed by an ID name tells the browser to jump to a specific section on a page. For example, href="#contact" scrolls to the element with id="contact". You can use this on the same page or combine it with a filename to jump to a section on another page.
Why does my link work on my computer but not after I upload it?
The most common reason is a path error or filename mismatch. Check that the file exists on your server in the exact location your href points to, and verify that capitalization matches. Also make sure you are using forward slashes, not backslashes, in your paths.