How to Add Hyperlink in HTML Code: Step-by-Step Guide

In the world of web development, hyperlinks are an essential component of navigating from one web page to another. Knowing how to add a hyperlink in HTML code is as fundamental as understanding HTML itself.

How to Code a Hyperlink in HTML (it's easier than you think!)
How to Code a Hyperlink in HTML (it's easier than you think!)

Hyperlinks are embedded with anchor, or anchor tag, inside HTML. They help to transfer the user from one HTML page to another with a single click. This guide will simply that for you.

How To Add Hyperlink In PDF: How To Create Hyperlink In PDF File For FREE
How To Add Hyperlink In PDF: How To Create Hyperlink In PDF File For FREE

Creating a Simple Hyperlink

A basic hyperlink can be created by enclosing the 'a' tag around the text, and providing a link with 'href' attribute. The 'href' attribute contains the web address you want the link to visit. Like so:

A Basic Guide to Links – How to Use HTML Hyperlinks
A Basic Guide to Links – How to Use HTML Hyperlinks

<a href="https://www.example.com">Click here</a>

Using Absolute URLs

HOW TO CREATE LINKS IN HTML
HOW TO CREATE LINKS IN HTML

Absolute URLs (Uniform Resource Locators) are full web addresses you see at the top of your browser when viewing a webpage. To use them, just put the URL in the href:

<a href="https://www.example.com/my-page">Visit my page</a>

Using Relative URLs

the text how to add hyperlink in pdf on a white background with black and yellow shapes
the text how to add hyperlink in pdf on a white background with black and yellow shapes

Relative URLs are links that point to a resource on the same domain as your current page. For instance, if your current page is 'https://www.example.com/my-other-page', using 'href="my-page"' will link to 'https://www.example.com/my-other-page/my-page'.

This is concise and more manageable when maintaining a website with many pages.

Linking to Internal and External Pages

Web Design in HTML & CSS – The Ultimate Lesson Plans Bundle
Web Design in HTML & CSS – The Ultimate Lesson Plans Bundle

Hyperlinks on a web page can either point to another page on the same site (internal link) or another web page (external link).

Internal links are typically used for navigating through different parts of a website, like from a homepage to an 'About' or 'Contact' page. They're useful for both users and search engine crawlers.

How to Hyperlink to a Specific Point within Your Posts
How to Hyperlink to a Specific Point within Your Posts
How to Add Links in HTML Coding HTML Tutorial for Beginners
How to Add Links in HTML Coding HTML Tutorial for Beginners
Learn to create links in HTML.
Learn to create links in HTML.
Difference Between Hypertext and Hyperlink
Difference Between Hypertext and Hyperlink
a screen shot of a web page with the words'html input types '
a screen shot of a web page with the words'html input types '
How to Create a Hyperlink in Microsoft Word
How to Create a Hyperlink in Microsoft Word
an image of a web page with the text'html input types'on it
an image of a web page with the text'html input types'on it
SEO for Lawyers: Definitive Guide to SEO for Law Firms in 2026
SEO for Lawyers: Definitive Guide to SEO for Law Firms in 2026
How To Create And Add A Button And Link To A HTML Website.
How To Create And Add A Button And Link To A HTML Website.
Links in HTML
Links in HTML
Internal vs external links (HTML basics) 👇
Internal vs external links (HTML basics) 👇
an image of a web page with the text'how to write a html list '
an image of a web page with the text'how to write a html list '
Squarespace 7.1 Tutorial: Customize Your Hyperlink Styles with These Squarespace CSS Tricks
Squarespace 7.1 Tutorial: Customize Your Hyperlink Styles with These Squarespace CSS Tricks
a table with instructions to use the code for an appliance or service center
a table with instructions to use the code for an appliance or service center
About HTML tags
About HTML tags
an image of a web page with the text'html link target attribute '
an image of a web page with the text'html link target attribute '
Create and manage hyperlinks
Create and manage hyperlinks
How to Add a Link in Canva (Insert Canva Hyperlink) - Blogging Guide
How to Add a Link in Canva (Insert Canva Hyperlink) - Blogging Guide
HTML Cheat Sheet 📄✨ Quick Guide for Beginners
HTML Cheat Sheet 📄✨ Quick Guide for Beginners
the ultimate guide to creating and formating tags
the ultimate guide to creating and formating tags

Internal Linking

Internal linking is done using relative URLs since both pages exist under the same domain. Simply use the file name or folder path in the 'href':

<a href="/about">About</a>

External Linking

For external links, absolute URLs are your go-to. You need to include the full address to guide users outside of your site:

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

Remember to stay clear of downloading information from external sources without proper sanitization to protect your site and users from malicious activity.

Defining the Target of a Link

By default, all hyperlinks open in the same window or browser tab. However, sometimes it's desirable for them to open in a new tab or window. This can be achieved by using the 'target' attribute.

New Tab or Window

To open a link in a new tab or window, apply the 'target' attribute with the value '_blank':

<a href="https://www.example.com" target="_blank">Open link in new tab</a>

Defining Named Targets

Named targets allow for creating multiple windows or tabs and naming them for later use. For example:

<a href="https://www.example.com/#target1">Visit target 1</a>

Then, in another place on the page, create a target:

<a id="target1"></a>

Now, when you click 'Visit target 1', it scrolls directly to 'target1'.

Mastery of adding hyperlinks in HTML code isn't complex once you've comprehended these methods. This skill will boost your web development endeavours considerably.

Related Articles

What Is Hyperlink In Html And Its Types Image Html Email Html Marquee Tag Replacement How To Change Hyperlink Text Color In Html Hyperlink Definition In Web Design 5 What Text Is Used To Create A Hyperlink In Html Image Tag In Email Marquee Tag In Html Example Codepen Css Marquee Tutorial Wrap Hyperlink Text In Html