How to Add a Link in HTML: Your Easy Step-by-Step Guide

By Cristian G. Guasch •  Updated: 09/18/23 •  10 min read

When it comes to designing a webpage, mastering the basics of HTML is essential. Among these fundamentals, understanding how to add a hyperlink, commonly known as a link, can’t be overstated. It’s the very mechanism that interconnects webpages on the internet. So today, I’ll be showing you exactly how to add a link in HTML.

Adding links in HTML is quite straightforward once you’ve got the hang of it. It involves using an ‘anchor’ tag denoted by <a>, followed by the href attribute which specifies the destination URL. But don’t worry if this sounds complicated right now — I’m here to break it down for you step-by-step.

Remember, getting comfortable with adding links will not only enable you to create interactive webpages but also contribute significantly towards your journey of becoming an accomplished web developer. Let’s dive into it and start creating clickable pathways that lead visitors from one webpage or site to another!

Understanding HTML: A Brief Overview

Diving right into it, let’s start with the basics. HTML, or HyperText Markup Language, is what gives shape and form to the websites we visit every day. It’s the backbone of web content and a pivotal player in how information gets presented online.

HTML uses tags as its primary building blocks. To illustrate, <a> is one such tag that you’ll come across pretty frequently. This tag helps you create hyperlinks on your webpage. Let’s look at an example:

<a href="">Visit our website</a>

In this snippet, href attributes are pointing to ““, making “Visit our website” a clickable link that takes users to the designated URL.

Tags aren’t limited to just links though; they extend to various elements on a webpage. For instance, <p> for paragraphs, <h1> for headlines, and so forth. Here’s how they work:

<h1>This is a headline</h1>
<p>This is a paragraph.</p>

Variations in using these tags can help structure your page better. Take the <h1> tag for example – there are variations like <h2><h3>, etc., which denote different levels of headings.

To sum up this brief overview–it’s crucial you grasp HTML’s fundamental principles if you’re trying to add links or handle any aspect of site design or management really! With some practice and persistence, you’ll be crafting intricate webpages before long!

Let’s dive right into the nuts and bolts of an HTML link. The most basic element you’ll need to understand is the anchor tag, often represented as <a>. This small yet powerful tag is what transforms a simple piece of text or image into a clickable link.

A typical HTML link looks something like this:

<a href="">Click me!</a>

Here, href stands for “hypertext reference” and it’s where we specify our URL. The text that follows— in this case, “Click me!”—is what users will see on their screen.

But there’s more to links than just sending your reader to another page. You can also use them for internal navigation within your site. For example, if I wanted to create a table of contents at the top of my blog post, I could make each item link directly to a different section:

  <li><a href="#intro">Introduction</a></li>
  <li><a href="#middle">Middle</a></li>
  <li><a href="#end">End</a></li>

<h2 id="intro">Introduction Section</h2>

<!-- content goes here -->

<h2 id="middle">Middle Section</h2>

<!-- content goes here -->

<h2 id="end">End Section</h2>

<!-- content goes here -->

Another neat feature is the ability to open links in new browser tabs by adding target="_blank" attribute within your <a> tag:

<a href="" target="_blank">Open in new tab!</a>

Understanding these elements and how they work together will give you much more flexibility when designing your site. And don’t forget about SEO! Using relevant keywords in your anchor text can help search engines understand what your page is about, boosting your visibility online. Just remember to keep it natural—overdoing it with keywords can actually harm your ranking.

Getting started with HTML is a breeze, especially when you’re learning how to add links. Let’s dive right into it by breaking down the process step by step.

First off, what you’ll need is the anchor tag <a>. This is your bread and butter when it comes to creating hyperlinks in HTML. It’s all about placing your URL in between these tags. For example: <a href="">Visit Example</a>. Here, “Visit Example” would appear as a clickable link leading to

Now let’s say you want to open that link in a new tab or window. That’s where the target attribute comes into play. Simply add target="_blank" within your anchor tag like this: <a href="" target="_blank">Visit Example</a>. Now clicking on “Visit Example” opens up a new tab with

There are times when we’d like our hyperlink text not only lead somewhere but also jump directly to a specific section of another page or even the same page. That’s doable! You’ll just have to use an ID for this purpose – known as ‘fragment identifier’. For instance: <a href="#section2">Go To Section 2</a> takes you straight down (or up) to wherever the id “section2” has been defined on that page.

And finally, if you want someone who clicks your link to immediately download something, there’s an attribute for that too! It goes like this: <a href="/files/myfile.pdf" download>Download My File</a>. Clicking on “Download My File”, guess what? Your file starts downloading automatically!

So there you go – some common ways of adding links in HTML and variations thereof using different attributes. Remember, practice makes perfect! So don’t hesitate to get your hands dirty and experiment with these examples. Alright, let’s talk about common mistakes in inserting links in HTML. It’s something that happens to the best of us, but I’m here to help you avoid them.

First off, one big mistake is forgetting to close the anchor tag. The syntax for creating a link in HTML is <a href="URL">Link Text</a>. If you forget to include the </a> at the end, it can mess up your entire webpage layout. Here’s an example:

<!-- Correct -->
<a href="">Click me!</a>

<!-- Incorrect -->
<a href="">Click me!

Another common error is leaving out quotation marks around the URL within href. Without these quotes, browsers might not interpret your link correctly. Take a look at this:

<!-- Correct -->
<a href="">Visit Example</a>

<!-- Incorrect -->
<a href=>Visit Example</a>

You might also accidentally use relative paths when you should be using absolute paths. Relative paths are used for linking to pages within your own website and usually start with a single / or just the filename. Absolute paths are full URLs used for external links.

<!-- Correct (for external links)-->
<a href="">Different Website Page</a>

<!-- Incorrect (for external links) -->
<a href="/page.html">Different Website Page</a>

Lastly, don’t forget about accessibility! Always include descriptive text inside your anchor tags so screen readers can understand where the link leads. For instance:

<!-- Accessible -->
<a href="">Search on Google</a>

<!-- Not Accessible -->
<a href="">Click here</a>

Remember these tips next time you’re adding links to your HTML code. It’ll save you a lot of debugging time and make your website more user-friendly!

I’ve guided you through the basics of adding a link in HTML, and by now, you should have a solid understanding of how to use the <a> tag. But remember, mastering HTML links isn’t just about knowing how to add a basic hyperlink. It’s also about understanding different attributes and how they alter the behavior of your links.

Take for example our standard link format:

<a href="">Visit Example</a>

This is what we’ve learned so far. A simple text that takes you to another page when clicked. But let’s not stop here.

HTML also allows us to open a link in a new tab using the target="_blank" attribute:

<a href="" target="_blank">Visit Example</a>

See? By simply adding this attribute, we ensure that users don’t navigate away from our page when they click on the link.

Let’s move forward. You can even set up an email link using mailto: inside your href attribute:

<a href="">Send Email</a>

And there you go! Now clicking on your link will open up the user’s default email client with a new draft addressed to

Now that I’ve shared these tricks with you, it’s time for some practice! Remember, repetition is key when learning any new skill. So I encourage you to incorporate these techniques into your next web project. And before you know it, you’ll be an expert at adding HTML links.

HTML provides us with a multitude of ways to enrich our user’s experience and mastering the art of adding links is just one piece of the puzzle. Keep exploring, keep experimenting, and most importantly, don’t stop learning!

Cristian G. Guasch

Hey! I'm Cristian Gonzalez, I created HTML Easy to help you learn HTML easily and fast.

Related articles