How to Add Links in HTML — HTML Tutorial #4 for Beginners

Hey friend! 👋

Welcome back to the HTML Basics for Beginners series!

Now it’s time to put one of the most important attributes to work.

Today we’re talking about links. 🔗

Think about it — what makes the internet the internet? It’s not just pages. It’s the ability to jump from one page to another in one click. From one website to another. From a heading to a section. From a button to your inbox.

That’s all links. Links are also known as Hyperlinks. And without them, the web would just be a collection of lonely, disconnected pages. 😢

Today you’re going to learn how to connect things together — like a pro. 🚀

What You’ll Learn Today about HTML Links

By the end of this tutorial, you’ll be able to:

✅ Create clickable links with the <a> tag
✅ Understand the difference between absolute and relative URLs
✅ Open links in a new tab
✅ Link to email addresses and phone numbers
✅ Turn an image into a clickable link
✅ Create jump links to sections on the same page
✅ Write accessible, SEO-friendly link text
✅ Build a mini project: My Favourite Websites 🌐

Let’s go! 🔥

Before You Start

Ready? Let’s dive in!

Step 1: Your Very First HTML Link

To create a link in HTML, we use the <a> tag.

The <a> stands for anchor — think of it as dropping an anchor that connects two places together. ⚓

But here’s the thing — the <a> tag on its own won’t do anything. It needs its best friend: the href attribute. href tells the browser exactly where to go when someone clicks the link.

Here’s the basic recipe:

Let’s break it down:

  • <a> → opens the anchor tag
  • href="https://www.codeboid.com" → the destination URL
  • Take me to Codeboid! → the clickable text the user sees
  • </a> → closes the anchor tag

When someone hovers over it in the browser, the cursor magically turns into a little hand 👆 — that’s how they know it’s clickable!

💡 Think of <a href> as:
A signpost. The text is what’s written on the sign. The href is the road it’s pointing to.

Practice Challenge 🎯

Create a new file called links.html and try this:

Open it in your browser and hover over the links — see the cursor turn into a hand? Click them and see where they go! 👆

Step 2: Absolute vs. Relative URLs

Now that you know how to write a link, let’s talk about the type of URL you put inside href.

There are two types — and knowing which one to use is really important. 👇

Absolute URLs — The Full Address

An absolute URL is the complete, full web address — starting with https://.

Use it when you’re linking to a different website:

Think of it like a full home address — street name, city, country, everything. Someone could find it from anywhere in the world.

Relative URLs — The Short Path

A relative URL is a short path that points to a page on your own website.

You don’t need https:// — just the file name or folder path.

💻 Try this on your computer! Just create the files below on your computer and open index.html in your browser.

To understand this properly, let’s create a small project with three files:

Here’s what each file looks like:

📄 index.html — your home page

📄 about.html — in the same folder as index.html

📄 pages/contact.html — inside the pages folder

💡 How to read ../:
Think of ../ as saying “go back one folder.”
contact.html lives inside pages/ — so ../ takes you back up to my-website/, where index.html lives.

Think of it like giving directions from where you already are. Instead of “350 5th Avenue, New York” you just say “third door on the left.” 😄

Quick Comparison

TypeWhen to UseExample
AbsoluteLinking to another websitehref="https://google.com"
RelativeLinking to your own pageshref="about.html"

💡 Simple rule:
Linking somewhere else on the internet? → Absolute
Linking to your own page? → Relative

Practice Challenge 🎯

Try this on your computer:

  1. Create a folder on your desktop called my-website
  2. Inside it, create index.html and about.html
  3. Inside my-website, create a folder called pages and add contact.html inside it
  4. Copy the three files above, open index.html in your browser and click between all the pages

All links should work perfectly! ✅

Step 3: Opening Links in a New Tab

Have you ever clicked a link and lost the page you were reading?

Super annoying, right? 😤

You can fix this for your visitors using the target attribute.

When you add target="_blank" to your link, the browser opens it in a brand new tab — so the original page stays open.

Try it — click the link and watch a new tab pop open! 🎉

See the Pen Codeboid – HTML Tutorial #4 — Hyperlink in a New Tab by Codeboid (@Codeboid) on CodePen.

⚠️ Security Tip

When using target="_blank", always add rel="noopener noreferrer" too:

Why? Without it, the new tab can technically access your page in the background. Adding rel="noopener noreferrer" closes that security gap. It’s a small habit that makes a big difference. 🔒

All target Values

While _blank is the one you’ll use most, here’s the full picture:

ValueWhat It Does
_blankOpens in a new tab or window
_selfOpens in the same tab (this is the default)
_parentOpens in the parent frame (used with iframes)
_topOpens in the full browser window

💡 In everyday web development, you’ll use _blank and _self 99% of the time.

Practice Challenge 🎯

Create a new file called links-new-tab.html and try this:

Click each link — they should all open in a new tab while this page stays open! 🎉

Step 4: Linking to Emails and Phone Numbers

Here’s a fun one — links don’t only point to web pages! 🤯

You can create links that open someone’s email app or dial a phone number directly.

Email Links → mailto:

Use mailto: inside the href to create a link that opens the user’s default email app with your address already filled in:

Click it and your email app pops open — ready to go! 📧

You can even pre-fill the subject line:

Phone Links → tel:

Use tel: to create a link that dials a number. On a mobile phone, tapping it opens the dialler automatically:

📱 This is really useful for business websites — one tap and the customer is calling you!

Putting It Together

Practice Challenge 🎯

Create a new file called contact.html and try this:

Click the email link — does your email app open? Tap the phone link on your mobile — does the dialler pop up? 📱

Step 5: Using an Image as a Link

Who says links have to be boring text? 😄

You can turn any image into a clickable link — just wrap the <img> tag inside the <a> tag!

📌 Note: We’re using <img> here just to show how image links work. We’ll cover everything about images — src, alt, width, height, image formats, and more — in full detail in Tutorial #5: How to Add Images in HTML. For now, just focus on how the link wrapping works!

See the Pen Codeboid – HTML Tutorial #4 — Image as Link by Codeboid (@Codeboid) on CodePen.

Now clicking the image takes you to Codeboid. This is exactly how logo links work on real websites! 🎯

💡 The rule: Whatever is between the <a>...</a> tags becomes clickable — text, images, or both.

⚠️ Important: Alt Text for Linked Images

When an image is used as a link, the alt text rules change slightly.

For a normal image, alt describes what the image looks like.
For a linked image, alt should describe where the link goes.

Why? Screen reader users navigate links by their label. If the label is just “blue logo with text,” they have no idea where it goes. Be helpful! 🦾

Practice Challenge 🎯

Create a new file called image-link.html and try this:

Step 6: Jump Links — Jumping Around a Page

Here’s a super useful trick for long pages.

You can create links that jump to a specific section on the same page when clicked — like a table of contents!

This is done in two steps:

Step A: Give the Section an id

First, add an id attribute to the element you want to jump to:

Step B: Link to That id Using #

Then create a link using # followed by the id name:

When someone clicks it, the page instantly scrolls to that heading! ✨

Full Example

See the Pen Codeboid – HTML Tutorial #4 — Jump Links by Codeboid (@Codeboid) on CodePen.

Back to Top Button

You can also add a “Back to Top” link using #top:

This is really common on long blog posts and documentation pages. You’ll find them everywhere once you start looking! 😄

Practice Challenge 🎯

Create a new file called jump-links.html and try this:

Click each navigation link — the page should jump to that section instantly. Click “Back to Top” and you’re back at the start! ✨

💡 The <br> tags just add spacing so the page is long enough to actually see the jumping effect!

Step 7: Write Accessible Link Text

Before you go build your amazing website, there’s one golden rule you need to know. 🏆

Never use “click here” as your link text.

It’s one of the most common mistakes beginners make — and it’s easy to fix!

Instead, use descriptive link text that clearly tells the user where they’re going — even when read out of context:

Why does this matter?

Two big reasons:

  1. Accessibility — People who use screen readers often jump from link to link. If every link says “click here,” they have absolutely no idea where anything goes. Descriptive text helps everyone.
  2. SEO — Search engines use link text to understand what the destination page is about. “Learn HTML for beginners” is far more useful to Google than “click here.”

💡 Quick test: Read your link text completely out of context. Does it still make sense? If yes — great! If no — rewrite it. ✅

Mini Project: My Favourite Websites 🌐

Let’s put everything together!

You’ll build a “My Favourite Websites” page with links, email, phone, image links, and a jump menu all in one.

Create a new file called favourite-websites.html:

What’s Happening in This Code?

id="top" on <h1> → lets the “Back to Top” link work
✅ Jump navigation at the top → links to three sections using #id
target="_blank" rel="noopener noreferrer" → opens external links safely in a new tab
✅ Images wrapped in <a> → clickable logos
✅ Descriptive alt text on linked images → describes the destination
mailto: → email link
tel: → phone link
<a href="#top"> → back to top button
&copy; → copyright symbol in the footer

Your Turn! 🎯

Customise this page:

  1. Add 2 more websites of your choice with their logos
  2. Replace the email and phone number with your own (or a made-up one)
  3. Add a fourth section — maybe “News” or “Tools”
  4. Change the jump navigation to match your new sections

Cheat Sheet (Save This!)

Quick Recap

Today you learned:

✅ How to create links with <a> and href
✅ The difference between absolute and relative URLs
✅ How to open links in a new tab with target="_blank"
✅ How to add rel="noopener noreferrer" for security
✅ How to create email links with mailto:
✅ How to create phone links with tel:
✅ How to turn images into clickable links
✅ How to write the correct alt text for linked images
✅ How to create jump links using id and #
✅ How to write accessible, descriptive link text
✅ Built a complete My Favourite Websites page

Common Mistakes to Avoid

❌ Forgetting href — without it, the link goes nowhere
❌ Using “click here” as link text — always be descriptive
❌ Forgetting https:// in absolute URLs — google.com alone won’t work
❌ Using target="_blank" without rel="noopener noreferrer" — security risk
❌ Forgetting to close </a> — everything after it becomes a link!
❌ Using the same id twice — id must be unique on the page
❌ Wrong alt text on linked images — describe the destination, not the looks

Get the Source Code

You can find all the code from this tutorial on GitHub:

Final Thoughts

Links are the heartbeat of the internet. 💓

Every website you’ve ever visited, every article you’ve ever read, every video you’ve ever clicked — they all got there because of links.

And now you know exactly how to build them yourself.

You know how to connect pages, open new tabs, send emails, dial phones, jump around a page, and make images clickable.

That’s not beginner stuff anymore — that’s real web development. 🚀

Keep practising. Keep building. Keep going. 🌱

What’s Next?

Coming Up in Tutorial #5: How to Add Images in HTML

You’ll learn:

  • How to add images with <img> and src
  • How to write great alt text
  • How to control image size with width and height
  • How to choose the right image format (JPEG, PNG, SVG, GIF)
  • Mini project: My Photo Gallery 🖼️

👉 Continue to Tutorial #5: How to Add Images in HTML →

Scroll to Top