How to Add Links in HTML

How to Add Links in HTML

In HTML, links are created using the anchor tag <a>. Links are used to navigate between different pages, sections within the same page, or to external websites. In this article, we will discuss the different ways to add links in HTML and provide examples of how to do so.

Creating a Basic Link

To create a basic link in HTML, you can use the following syntax:

<!DOCTYPE html>
<html>
<body>

<a href="https://how2html.com">Visit How2HTML</a>

</body>
</html>

Output:

How to Add Links in HTML

In this example, a basic link is created that directs the user to “how2html.com” when clicked.

Adding a Link to an Image

You can also make an image clickable by wrapping it in an anchor tag. Here’s an example:

<!DOCTYPE html>
<html>
<body>

<a href="https://how2html.com">
  <img src="https://how2html.com/wp-content/themes/dux/img/logo.png" alt="Image" style="width:100px;height:100px;">
</a>

</body>
</html>

Output:

How to Add Links in HTML

In this example, when the image is clicked, the user will be directed to “how2html.com”.

Creating a Link to a Specific Section on a Page

You can create links that navigate to a specific section on the same page by using anchor tags with the id attribute. Here’s how you can do it:

<!DOCTYPE html>
<html>
<body>

<h2 id="section1">Section 1</h2>
<p>This is Section 1.</p>

<h2 id="section2">Section 2</h2>
<p>This is Section 2.</p>

<a href="#section1">Go to Section 1</a>
<a href="#section2">Go to Section 2</a>

</body>
</html>

Output:

How to Add Links in HTML

In this example, when the user clicks the link, they will be directed to the specified section on the same page.

Creating a Link to an Email Address

You can create links that open the default email client with a pre-filled email address. Here’s an example:

<!DOCTYPE html>
<html>
<body>

<a href="mailto:info@how2html.com">Email Us</a>

</body>
</html>

Output:

How to Add Links in HTML

In this example, when the user clicks the link, the default email client will open with the email address pre-filled.

Creating a Link to Download a File

You can create links that allow the user to download a file by specifying the file path in the href attribute. Here’s an example:

<!DOCTYPE html>
<html>
<body>

<a href="download.pdf" download>Download PDF</a>

</body>
</html>

Output:

How to Add Links in HTML

In this example, when the user clicks the link, the PDF file will be downloaded to their device.

Adding Links with External Websites

You can create links that direct the user to external websites by specifying the URL in the href attribute. Here’s an example:

<!DOCTYPE html>
<html>
<body>

<a href="https://how2html.com">Visit How2HTML</a>

</body>
</html>

Output:

How to Add Links in HTML

In this example, the user will be directed to “how2html.com” when they click the link.

Linking to a Website in a New Tab

You can make links open in a new tab by using the target attribute with the value _blank. Here’s an example:

<!DOCTYPE html>
<html>
<body>

<a href="https://how2html.com" target="_blank">Visit How2HTML</a>

</body>
</html>

Output:

How to Add Links in HTML

In this example, when the user clicks the link, “how2html.com” will open in a new tab.

Creating a Link with a Tooltip

You can add a tooltip to a link by using the title attribute. Here’s an example:

<!DOCTYPE html>
<html>
<body>

<a href="https://how2html.com" title="Visit How2HTML">How2HTML</a>

</body>
</html>

Output:

How to Add Links in HTML

In this example, when the user hovers over the link, a tooltip will appear with the specified text.

Linking to a Specific Section on Another Page

You can create links that navigate to a specific section on another page by using the full URL followed by the # symbol and the id of the section. Here’s an example:

<!DOCTYPE html>
<html>
<body>

<a href="https://how2html.com/#section1">Go to Section 1</a>

</body>
</html>

Output:

How to Add Links in HTML

In this example, when the user clicks the link, they will be directed to Section 1 on the page at “how2html.com”.

Styling Links with CSS

You can style links using CSS to change their appearance. Here’s an example of styling links to have a blue color and no underline:

<!DOCTYPE html>
<html>
<head>
<style>
a {
  color: blue;
  text-decoration: none;
}
</style>
</head>
<body>

<a href="https://how2html.com">Visit How2HTML</a>

</body>
</html>

Output:

How to Add Links in HTML

In this example, the link text will be displayed in blue with no underline.

Displaying Links as Buttons

You can style links to look like buttons by applying CSS styles. Here’s an example:

<!DOCTYPE html>
<html>
<head>
<style>
.button {
  display: inline-block;
  padding: 10px 20px;
  background-color: blue;
  color: white;
  text-decoration: none;
}
</style>
</head>
<body>

<a href="https://how2html.com" class="button">Visit How2HTML</a>

</body>
</html>

Output:

How to Add Links in HTML

In this example, the link will be displayed as a button with a blue background and white text.

Creating a Link with a Hover Effect

You can add a hover effect to links using CSS. Here’s an example of changing the link color on hover:

<!DOCTYPE html>
<html>
<head>
<style>
a:hover {
  color: red;
}
</style>
</head>
<body>

<a href="https://how2html.com">Visit How2HTML</a>

</body>
</html>

Output:

How to Add Links in HTML

In this example, when the user hovers over the link, the color will change to red.

Making Links Underlined on Hover

You can add an underline to links on hover using CSS. Here’s an example:

<!DOCTYPE html>
<html>
<head>
<style>
a {
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}
</style>
</head>
<body>

<a href="https://how2html.com">Visit How2HTML</a>

</body>
</html>

Output:

How to Add Links in HTML

In this example, when the user hovers over the link, an underline will appear.

Linking to Different Sections on the Same Page

You can create links that navigate to different sections on the same page by using anchor tags with the href attribute set to the id of the section. Here’s an example:

<!DOCTYPE html>
<html>
<body>

<h2 id="section1">Section 1</h2>
<p>This is Section 1.</p>

<h2 id="section2">Section 2</h2>
<p>This is Section 2.</p>

<a href="#section1">Go to Section 1</a>
<a href="#section2">Go to Section 2</a>

</body>
</html>

Output:

How to Add Links in HTML

In this example, when the user clicks the link, they will be directed to the specified section on the same page.

Creating a Link to a Different Website

You can create links that direct the user to a different website by specifying the URL in the href attribute. Here’s an example:

<!DOCTYPE html>
<html>
<body>

<a href="https://how2html.com">Visit How2HTML</a>

</body>
</html>

Output:

How to Add Links in HTML

In this example, when the user clicks the link, they will be directed to “how2html.com”.

Linking to an Email Address

You can create links that open the default email client with a pre-filled email address. Here’s an example:

<!DOCTYPE html>
<html>
<body>

<a href="mailto:info@how2html.com">Email Us</a>

</body>
</html>

Output:

How to Add Links in HTML

In this example, when the user clicks the link, the default email client willopen with the email address “info@how2html.com” pre-filled.

Creating a Link to Download a File

You can create links that allow the user to download a file by specifying the file path in the href attribute. Here’s an example:

<!DOCTYPE html>
<html>
<body>

<a href="download.pdf" download>Download PDF</a>

</body>
</html>

Output:

How to Add Links in HTML

In this example, when the user clicks the link, the PDF file will be downloaded to their device.

Adding Links with External Websites

You can create links that direct the user to external websites by specifying the URL in the href attribute. Here’s an example:

<!DOCTYPE html>
<html>
<body>

<a href="https://how2html.com">Visit How2HTML</a>

</body>
</html>

Output:

How to Add Links in HTML

In this example, the user will be directed to “how2html.com” when they click the link.

Linking to a Website in a New Tab

You can make links open in a new tab by using the target attribute with the value _blank. Here’s an example:

<!DOCTYPE html>
<html>
<body>

<a href="https://how2html.com" target="_blank">Visit How2HTML</a>

</body>
</html>

Output:

How to Add Links in HTML

In this example, when the user clicks the link, “how2html.com” will open in a new tab.

Creating a Link with a Tooltip

You can add a tooltip to a link by using the title attribute. Here’s an example:

<!DOCTYPE html>
<html>
<body>

<a href="https://how2html.com" title="Visit How2HTML">How2HTML</a>

</body>
</html>

Output:

How to Add Links in HTML

In this example, when the user hovers over the link, a tooltip will appear with the specified text.

Linking to a Specific Section on Another Page

You can create links that navigate to a specific section on another page by using the full URL followed by the # symbol and the id of the section. Here’s an example:

<!DOCTYPE html>
<html>
<body>

<a href="https://how2html.com/#section1">Go to Section 1</a>

</body>
</html>

Output:

How to Add Links in HTML

In this example, when the user clicks the link, they will be directed to Section 1 on the page at “how2html.com”.

Styling Links with CSS

You can style links using CSS to change their appearance. Here’s an example of styling links to have a blue color and no underline:

<!DOCTYPE html>
<html>
<head>
<style>
a {
  color: blue;
  text-decoration: none;
}
</style>
</head>
<body>

<a href="https://how2html.com">Visit How2HTML</a>

</body>
</html>

Output:

How to Add Links in HTML

In this example, the link text will be displayed in blue with no underline.

Displaying Links as Buttons

You can style links to look like buttons by applying CSS styles. Here’s an example:

<!DOCTYPE html>
<html>
<head>
<style>
.button {
  display: inline-block;
  padding: 10px 20px;
  background-color: blue;
  color: white;
  text-decoration: none;
}
</style>
</head>
<body>

<a href="https://how2html.com" class="button">Visit How2HTML</a>

</body>
</html>

Output:

How to Add Links in HTML

In this example, the link will be displayed as a button with a blue background and white text.

Creating a Link with a Hover Effect

You can add a hover effect to links using CSS. Here’s an example of changing the link color on hover:

<!DOCTYPE html>
<html>
<head>
<style>
a:hover {
  color: red;
}
</style>
</head>
<body>

<a href="https://how2html.com">Visit How2HTML</a>

</body>
</html>

Output:

How to Add Links in HTML

In this example, when the user hovers over the link, the color will change to red.

Making Links Underlined on Hover

You can add an underline to links on hover using CSS. Here’s an example:

<!DOCTYPE html>
<html>
<head>
<style>
a {
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}
</style>
</head>
<body>

<a href="https://how2html.com">Visit How2HTML</a>

</body>
</html>

Output:

How to Add Links in HTML

In this example, when the user hovers over the link, an underline will appear.

Linking to Different Sections on the Same Page

You can create links that navigate to different sections on the same page by using anchor tags with the href attribute set to the id of the section. Here’s an example:

<!DOCTYPE html>
<html>
<body>

<h2 id="section1">Section 1</h2>
<p>This is Section 1.</p>

<h2 id="section2">Section 2</h2>
<p>This is Section 2.</p>

<a href="#section1">Go to Section 1</a>
<a href="#section2">Go to Section 2</a>

</body>
</html>

Output:

How to Add Links in HTML

In this example, when the user clicks the link, they will be directed to the specified section on the same page.

Creating a Link to a Different Website

You can create links that direct the user to a different website by specifying the URL in the href attribute. Here’s an example:

<!DOCTYPE html>
<html>
<body>

<a href="https://how2html.com">Visit How2HTML</a>

</body>
</html>

Output:

How to Add Links in HTML

In this example, when the user clicks the link, they will be directed to “how2html.com”.

Linking to an Email Address

You can create links that open the default email client with a pre-filled email address. Here’s an example:

<!DOCTYPE html>
<html>
<body>

<a href="mailto:info@how2html.com">Email Us</a>

</body>
</html>

Output:

How to Add Links in HTML

In this example, when the user clicks the link, the default email client will open with the email address “info@how2html.com” pre-filled.

Creating a Link to Download a File

You can create links that allow the user to download a file by specifying the file path in the href attribute. Here’s an example:

<!DOCTYPE html>
<html>
<body>

<a href="download.pdf" download>Download PDF</a>

</body>
</html>

Output:

How to Add Links in HTML

In this example, when the user clicks the link, the PDF file will be downloaded to their device.

Adding Links with External Websites

You can create links that direct the user to external websites by specifying the URL in the href attribute. Here’s an example:

<!DOCTYPE html>
<html>
<body>

<a href="https://how2html.com">Visit How2HTML</a>

</body>
</html>

Output:

How to Add Links in HTML

In this example, the user will be directed to “how2html.com” when they click the link.

Linking to a Website in a New Tab

You can make links open in a new tab by using the target attribute with the value _blank. Here’s an example:

<!DOCTYPE html>
<html>
<body>

<a href="https://how2html.com" target="_blank">Visit How2HTML</a>

</body>
</html>

Output:

How to Add Links in HTML

In this example, when the user clicks the link, “how2html.com” will open in a new tab.

Creating a Link with a Tooltip

You can add a tooltip to a link by using the title attribute. Here’s an example:

<!DOCTYPE html>
<html>
<body>

<a href="https://how2html.com" title="Visit How2HTML">How2HTML</a>

</body>
</html>

Output:

How to Add Links in HTML

In this example, when the user hovers over the link, a tooltip will appear with the specified text.

Linking to a Specific Section on Another Page

You can create links that navigate to a specific section on another page by using the full URL followed by the # symbol and the id of the section. Here’s an example:

<!DOCTYPE html>
<html>
<body>

<a href="https://how2html.com/#section1">Go to Section 1</a>

</body>
</html>

Output:

How to Add Links in HTML

In this example,when the user clicks the link, they will be directed to Section 1 on the page at “how2html.com”.

Styling Links with CSS

You can style links using CSS to change their appearance. Here’s an example of styling links to have a blue color and no underline:

<!DOCTYPE html>
<html>
<head>
<style>
a {
  color: blue;
  text-decoration: none;
}
</style>
</head>
<body>

<a href="https://how2html.com">Visit How2HTML</a>

</body>
</html>

Output:

How to Add Links in HTML

In this example, the link text will be displayed in blue with no underline.

Displaying Links as Buttons

You can style links to look like buttons by applying CSS styles. Here’s an example:

<!DOCTYPE html>
<html>
<head>
<style>
.button {
  display: inline-block;
  padding: 10px 20px;
  background-color: blue;
  color: white;
  text-decoration: none;
}
</style>
</head>
<body>

<a href="https://how2html.com" class="button">Visit How2HTML</a>

</body>
</html>

Output:

How to Add Links in HTML

In this example, the link will be displayed as a button with a blue background and white text.

Creating a Link with a Hover Effect

You can add a hover effect to links using CSS. Here’s an example of changing the link color on hover:

<!DOCTYPE html>
<html>
<head>
<style>
a:hover {
  color: red;
}
</style>
</head>
<body>

<a href="https://how2html.com">Visit How2HTML</a>

</body>
</html>

Output:

How to Add Links in HTML

In this example, when the user hovers over the link, the color will change to red.

Making Links Underlined on Hover

You can add an underline to links on hover using CSS. Here’s an example:

<!DOCTYPE html>
<html>
<head>
<style>
a {
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}
</style>
</head>
<body>

<a href="https://how2html.com">Visit How2HTML</a>

</body>
</html>

Output:

How to Add Links in HTML

In this example, when the user hovers over the link, an underline will appear.

Linking to Different Sections on the Same Page

You can create links that navigate to different sections on the same page by using anchor tags with the href attribute set to the id of the section. Here’s an example:

<!DOCTYPE html>
<html>
<body>

<h2 id="section1">Section 1</h2>
<p>This is Section 1.</p>

<h2 id="section2">Section 2</h2>
<p>This is Section 2.</p>

<a href="#section1">Go to Section 1</a>
<a href="#section2">Go to Section 2</a>

</body>
</html>

Output:

How to Add Links in HTML

In this example, when the user clicks the link, they will be directed to the specified section on the same page.

Creating a Link to a Different Website

You can create links that direct the user to a different website by specifying the URL in the href attribute. Here’s an example:

<!DOCTYPE html>
<html>
<body>

<a href="https://how2html.com">Visit How2HTML</a>

</body>
</html>

Output:

How to Add Links in HTML

In this example, when the user clicks the link, they will be directed to “how2html.com”.

Like(0)

HTML Articles