What is a Hyperlink? HTML Links Explained with Examples (2024)

/ #beginners guide
What is a Hyperlink? HTML Links Explained with Examples (1)
Hillary Nyakundi
What is a Hyperlink? HTML Links Explained with Examples (2)

Let's begin with a quick question: How did you land on this article and this site today?

Well, quite literally, by clicking or tapping on a link, right? That's how powerful this element is – it will get you to any part of the Internet just by clicking on a link.

So, what are links and hyperlinks in HTML?

What are Links and Hyperlinks in HTML?

A link is a chain that connects pages both within a website and to other websites. Without links, we wouldn't have any websites.

For example, let's have a look at this URL, https://www.freecodecamp.org/. When you type it in the address bar it will take you to the official freeCodeCamp site.

In simpler terms we can say that links are just the web addresses of web page that allow you to connect with different servers.

Perhaps you are wondering, then, what a Hyperlink might be? Well, they are what allows us to link documents to other documents or resources via refrences called anchor tags. They are a fundamental concept behind the World Wide Web which makes navigation between web pages easier via links.

Hyperlinks can be presented in different forms, like an image, icon, text, or any type of visible element that, when clicked, redirects you to a specified url.

For example, if you were to click HERE, you will land in my profile with a list of my other articles. That's a hyperlink.

How to Create Links in HTML

How to use <a> links

You can create a basic link by wrapping the text (or any other related content) in the <a></a> element and using the href attribute which contains the address.

Here's an example in action:

<a href="https://www.freecodecamp.org">Visit: Freecode Camp!</a>

How to style links

There are usually links inserted in the .html file that link the main to the styling and funtionality file. And they're typically named with the .css and .js file extensions.

Here's how to link to a CSS file:

<!DOCTYPE html><html><head> <link rel="stylesheet" href="styles.css"></head><body><h1>This is a heading</h1><p>This is a paragraph.</p></body></html>

And here's how to link to a JS file. You can either place what you want linked in the head or body tag.

<!DOCTYPE html><html><head> <script src="myScript.js"></script></head><body><h1>This is a heading</h1><p>This is a paragraph.</p></body></html>

How to Link Within a Site

Links to different page within a Site

You use this type of link to direct a user to different pages on the same site.

Take a case where your site has 5 pages. You'll want a user to be able to access all the pages from one point, like the navbar.

First you will have to create all the pages and then link them. In this case we will do it like this:

<nav> <ul> <li><a href="home.html">Home</a></li> <li><a href="services.html">Services</a></li> <li><a href="pricing.html">Pricing</a></li> <li><a href="about.html">About</a></li> <li><a href="contact.html">Contact</a></li> </ul></nav>

The above example will link to different parts of the site – the 'Home' page, 'Services', 'Pricing', and 'About', in that order. Writing only the name of the file is enough because all the work is shared in the same work folder.

How to Link to a specific section of a site

Let's say that, somewhere on your site, you mentioned a particular topic or page. And you would like your readers or visitors to jump straight to that section with a click.

First you will have to add the id attribute to that section of the page. Maybe it is a paragraph – if so, this is how it would look:

<p id="detailed-info"> Read more on Upcoming Events </p>

After this in your link add the id in the href:

<a href="#detailed-info"> Read more about upcoming events </a>

This code will take them right to the Upcoming Events section.

Other Types of Links in HTML

How to Link to a Downloadable file

When you want to link to a resource that a user needs to download rather than open in the browser, you can use the download attribute. This provides a default save filename.

The download attribute is great for PDFs, image files, video and audio clips, and other media content that you would like users to save on their computer or mobile device.

Here's an example with a download link:

<a href="https://download.mozilla.org/?product=firefox-latest-ssl&os=win64&lang=en-US" download="firefox-latest-64bit-installer.exe"> Download Latest Firefox for Windows (64-bit) (English, US)</a>

How to Add E-mail Links

Email Links allow us to create hyperlinks to an email address. You can create these links using the HTML <a></a> tag – but in this case, instead of passing a URL, we pass the recipient’s email address.

You use the mailto attribute to specify the email address in your anchor tag.

for example:

<a href="mailto:[email protected]">Send email to Me</a>

In addition to the email address, you can provide other information. In fact, any standard mail header fields can be added to the mailto URL you provide. The most commonly used are "subject", "cc", and "body".

Here's an example that includes a cc, bcc, subject, and body:

<a href="mailto:[email protected][email protected]&[email protected]&subject=The%20subject%20of%20the%20email&body=The%20body%20of%20the%20email"> Send mail with cc, bcc, subject and body</a>

HTML Link Attributes

HTML links have various attributes that you can use to provide more speicifc information. Here are some of the most commonly used.

  1. href attributeThe href attribute defines the target URL address for an HTML link. It makes the marked word or phrase clickable. The href attribute creates a hyperlink to another web page, and HTML links would not work as intended without it.

  2. target attributeThe target attribute defines where the HTML link will be opened. Ever visited a website and when you click on a link it automatically opens in a new tab? Well that's the work of this attribute.

Here are all the possible options you can use with the target attribute:

  • -blank => Opens the link in a new tab. Mostly used to avoid losing a site's visitors. By default, when a user clicks a link it opens in the same tab – but this changes that.

    <a href= "https://www.freecodecamp.org/" target="_blank"> freeCodeCamp</a>
  • _self => Loads the URL in the same window or the tab where it was clicked. This is usually the default and does not need to be specified.

    <a href="https://www.freecodecamp.org" target="_self">freeCodeCamp</a>
  • _parent => Loads the URL in the parent frame. It’s only used with frames.

    <a href="https://www.freecodecamp.org" target="_parent">freeCodeCamp</a>
  • _top => Loads the linked document in the full body of the window.

    <a href="https://www.freecodecamp.org" target="_top">freeCodeCamp</a>
  • title attributeThe title attribute outlines extra information about the link’s purpose. If a user hovers their mouse over the link, a tooltip will appear which describes the objective, title, or any other information about the link:

<a href="https://www.freecodecamp.org" title="Link to free learning Resources">Learn to code</a>

Quick HTML Link Tips and Recap

In this article, we learned all about links and hyperlinks in HTML. Here are some final tips to help you work with links.

Firt, when you're using an image as a link, it's always a good idea to include the alt tag with the text. This provides alternative text that's displayed in case the picture doesn't load.

Second, you should practise specifying the language of the document which the anchor is linked to using the hreflang attribute.

<a href="https://www.freecodecamp.org" hreflang="en">Freecode Camp</a>

The Web is really just a library of hyperlinked documents where the anchor tags act as bridges between related documents.

We have seen how to use links and how to create them, and why they are important in web development.

It's time to go practise and perfect your new skill.

Enjoy Coding ❤

ADVERTIsem*nT

ADVERTIsem*nT

ADVERTIsem*nT

ADVERTIsem*nT

ADVERTIsem*nT

ADVERTIsem*nT

ADVERTIsem*nT

ADVERTIsem*nT

What is a Hyperlink? HTML Links Explained with Examples (3)
Hillary Nyakundi

I'm a Growing Developer with a keen interest in technology, particularly in the areas of open-source and Python. As a passionate technical writer, I aim to share my knowledge with other developers through informative articles that help them grow and succeed.

If you read this far, thank the author to show them you care.

Learn to code for free. freeCodeCamp's open source curriculum has helped more than 40,000 people get jobs as developers. Get started

ADVERTIsem*nT

What is a Hyperlink? HTML Links Explained with Examples (2024)

FAQs

What is a Hyperlink? HTML Links Explained with Examples? ›

Hyperlink is any link in a document that directs the user to any other part of the same document, any other document or any other part of another document. It is written by <a> tag in HTML. So, when you see a link in the HTML, it is a hyperlink. Any text with a set of hyperlinks is called a hypertext.

What is a hyperlink in HTML with examples? ›

Hyperlinks can be presented in different forms, like an image, icon, text, or any type of visible element that, when clicked, redirects you to a specified url. For example, if you were to click HERE, you will land in my profile with a list of my other articles. That's a hyperlink.

What is hyperlink simple answer? ›

In a website, a hyperlink (or link) is an item like a word or button that points to another location. When you click on a link, the link will take you to the target of the link, which may be a webpage, document or other online content. Websites use hyperlinks as a way to navigate online content.

What is a hyperlink in a computer with an example? ›

In computing, a hyperlink, or simply a link, is a digital reference to data that the user can follow or be guided to by clicking or tapping. A hyperlink points to a whole document or to a specific element within a document. Hypertext is text with hyperlinks. The text that is linked from is known as anchor text.

What is the correct HTML for a hyperlink as an example? ›

To make a hyperlink in an HTML page, use the <a> and </a> tags, which are the tags used to define the links. The <a> tag indicates where the hyperlink starts and the </a> tag indicates where it ends. Whatever text gets added inside these tags, will work as a hyperlink. Add the URL for the link in the <a herf=" ">.

What are the types of hyperlinks explain with example? ›

There are four types of hyperlinks. Text hyperlink – Uses a word or phrase to take visitors to another page, file or document. Image hyperlink – Uses an image to take visitors to another page, file or document. Bookmark hyperlink – Uses text or an image to take visitors to another part of a web page.

What is an example of a URL hyperlink? ›

Use this code to add a Link to a page:
  • <a href=“http://Internet URL goes here.”> ...
  • Code example: <a href=http://www.example.com>Example</a>
  • <img src=“image name goes here” align=“Use left, right or center”>
  • Code example: <img src= “house.jpg” align=“center”>
  • <a href=“mailto:[email protected]”>E-mail Us</a>

What is a hyperlink for dummies? ›

Hyperlinks allow us to link documents to other documents or resources, link to specific parts of documents, or make apps available at a web address. Almost any web content can be converted to a link so that when clicked or otherwise activated the web browser goes to another web address (URL).

What is the difference between link and hyperlink with example? ›

What are the differences between link and hyperlink? A link is simply a connection between two different points, whereas a hyperlink is a type of link that uses HTML code which when clicked on will direct the user to another internet page. This can be within the same website, or to an external website.

What is an example of a hyperlink in word? ›

You can also create a hyperlink to a blank email message by simply typing the address in the document. For example, type [email protected], and Microsoft 365 creates the hyperlink for you (unless you turned off automatic formatting of hyperlinks).

How to make a text a link in HTML? ›

For most content, including text, you can simply turn them into a clickable link by wrapping them between the opening and closing <a></a> tags. Whatever content is inside of the tags will become a clickable link. For example, this will turn an image into a clickable link.

What happens when you click a hypertext link? ›

Long story short - When you click on a link, the browser takes you or “redirects” you to the site that link represents. Your browser finds the IP address of the server that hosts the site using a method called DNS(Domain Name System).

What is the difference between hypertext and hyperlink in HTML? ›

Hyperlink is any link in a document that directs the user to any other part of the same document, any other document or any other part of another document. It is written by <a> tag in HTML. So, when you see a link in the HTML, it is a hyperlink. Any text with a set of hyperlinks is called a hypertext.

What is HTML hyperlink and example? ›

HTML links are hyperlinks. You can click on a link and jump to another document. When you move the mouse over a link, the mouse arrow will turn into a little hand. Note: A link does not have to be text. A link can be an image or any other HTML element!

What are the two basic parts of a hyperlink provide an example? ›

Hyperlinks have two basic parts: the address (URL) of the webpage and the display text. For example, the address could be http://www.popsci.com, and the display text could be Popular Science Magazine. When you create a hyperlink in Word, you'll be able to choose both the address and the display text.

What are the rules for hyperlinks in HTML? ›

The <a> HTML element (or anchor element), with its href attribute, creates a hyperlink to web pages, files, email addresses, locations in the same page, or anything else a URL can address. Content within each <a> should indicate the link's destination.

What is the difference between a link and a hyperlink? ›

What are the differences between link and hyperlink? A link is simply a connection between two different points, whereas a hyperlink is a type of link that uses HTML code which when clicked on will direct the user to another internet page. This can be within the same website, or to an external website.

What does a hyperlink look like? ›

What is a hyperlink example? Any image or text that, when clicked, sends you to another webpage or to another document or file. Often, hyperlinks will look like this: hyperlink (underlined and a different color than other text).

How do I turn a URL into a hyperlink? ›

Create a hyperlink to a location on the web

Select the text or picture that you want to display as a hyperlink. Link. You can also right-click the text or picture and click Link on the shortcut menu. In the Insert Hyperlink box, type or paste your link in the Address box.

Does a hyperlink apply to text only? ›

No, a hyperlink can apply to other elements besides text, such as images, charts, icons, etc.

Top Articles
How TikTok gifts work and where your money ends up
Britannica Money
Walgreens Harry Edgemoor
Walgreens Boots Alliance, Inc. (WBA) Stock Price, News, Quote & History - Yahoo Finance
Top 11 Best Bloxburg House Ideas in Roblox - NeuralGamer
Skyward Houston County
The Largest Banks - ​​How to Transfer Money With Only Card Number and CVV (2024)
Pangphip Application
Ret Paladin Phase 2 Bis Wotlk
Mate Me If You May Sapir Englard Pdf
CKS is only available in the UK | NICE
Sprague Brook Park Camping Reservations
Tanger Outlets Sevierville Directory Map
Slapstick Sound Effect Crossword
Buckaroo Blog
Housing Intranet Unt
Tiger Island Hunting Club
Culos Grandes Ricos
U/Apprenhensive_You8924
Hair Love Salon Bradley Beach
Hilo Hi Craigslist
Www.craigslist.com Savannah Ga
Zillow Group Stock Price | ZG Stock Quote, News, and History | Markets Insider
When Does Subway Open And Close
Hannaford Weekly Flyer Manchester Nh
Bolsa Feels Bad For Sancho's Loss.
At 25 Years, Understanding The Longevity Of Craigslist
Sinfuldeed Leaked
Does Royal Honey Work For Erectile Dysfunction - SCOBES-AR
Ugly Daughter From Grown Ups
Does Circle K Sell Elf Bars
Puerto Rico Pictures and Facts
Frostbite Blaster
Clark County Ky Busted Newspaper
Heavenly Delusion Gif
Andhra Jyothi Telugu News Paper
Go Upstate Mugshots Gaffney Sc
Metra Schedule Ravinia To Chicago
Dynavax Technologies Corp (DVAX)
Wal-Mart 2516 Directory
Chatropolis Call Me
What Does Code 898 Mean On Irs Transcript
Captain Billy's Whiz Bang, Vol 1, No. 11, August, 1920&#10;America's Magazine of Wit, Humor and Filosophy
About My Father Showtimes Near Amc Rockford 16
Cnp Tx Venmo
Weekly Math Review Q2 7 Answer Key
Woody Folsom Overflow Inventory
Canonnier Beachcomber Golf Resort & Spa (Pointe aux Canonniers): Alle Infos zum Hotel
Hughie Francis Foley – Marinermath
Erica Mena Net Worth Forbes
Electric Toothbrush Feature Crossword
The Ultimate Guide To 5 Movierulz. Com: Exploring The World Of Online Movies
Latest Posts
Article information

Author: Barbera Armstrong

Last Updated:

Views: 5639

Rating: 4.9 / 5 (79 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Barbera Armstrong

Birthday: 1992-09-12

Address: Suite 993 99852 Daugherty Causeway, Ritchiehaven, VT 49630

Phone: +5026838435397

Job: National Engineer

Hobby: Listening to music, Board games, Photography, Ice skating, LARPing, Kite flying, Rugby

Introduction: My name is Barbera Armstrong, I am a lovely, delightful, cooperative, funny, enchanting, vivacious, tender person who loves writing and wants to share my knowledge and understanding with you.