HTML Links 🔗

beginner
12 min

HTML Links 🔗

Welcome to our comprehensive guide on HTML Links! This tutorial is designed to help you understand everything about hyperlinks in HTML, from the basics to advanced concepts. Let's get started! 🎯

What are HTML Links? 📝

HTML links, also known as hyperlinks, are used to connect different web pages or parts of a web page. They enable users to navigate between pages or jump to specific sections, making the web a more interconnected and accessible place.

Creating HTML Links 💡

Basic Syntax

To create a hyperlink in HTML, you use the <a> tag. The basic syntax is as follows:

html
<a href="link-url">Link Text</a>

Replace "link-url" with the URL you want to link to, and "Link Text" with the text that will appear as the clickable link.

Relative and Absolute URLs

When linking to other pages on the same website, you can use either a relative URL (starts with / or no /) or an absolute URL (starts with http:// or https://).

  • Relative URL: If the linked page is in the same domain, use a relative URL. For example:
html
<a href="/about-us">About Us</a>
  • Absolute URL: If the linked page is on a different domain, use an absolute URL. For example:
html
<a href="https://www.example.com">Example Website</a>

Linking to Specific Sections 💡

You can link to specific sections within a web page by using the id attribute. Here's an example:

html
<!DOCTYPE html> <html> <head> <title>Page with Sections</title> </head> <body> <h2 id="section1">Section 1</h2> <h2 id="section2">Section 2</h2> <a href="#section1">Link to Section 1</a> <a href="#section2">Link to Section 2</a> </body> </html>

In this example, we have two sections with id attributes (#section1 and #section2). The links point to these sections using the # symbol followed by the id value.

Opening Links in New Tabs 💡

By default, clicking a link will navigate the user away from the current page. If you want a link to open in a new tab, use the target attribute and set its value to _blank.

html
<a href="https://www.example.com" target="_blank">Example Website (opens in a new tab)</a>

Linking to Email Addresses 💡

You can create a link that opens the user's email client with a pre-filled to field. To do this, use the mailto: protocol followed by the email address.

html
<a href="mailto:example@example.com">Email Example</a>

Quiz 📝

Quick Quiz
Question 1 of 1

What tag is used for creating a hyperlink in HTML?


That's it for this lesson on HTML Links! In the next lesson, we will dive deeper into more HTML elements, making you more proficient in creating engaging and interactive web pages. 📝 Keep learning, and happy coding! 💡🎯