How to Create Links to Other Pages in HTML ?
Last Updated :
01 Apr, 2024
HTML links are like pathways on the internet. They connect one webpage to another. Imagine a link as having two parts: a starting point (where you click) and an endpoint (where you end up). When you click on a link, you're basically starting at one point (the anchor) and moving to another (the destination). These links are made using anchor tags in HTML, which have a special attribute called "href" that tells your browser where to go when you click the link. Links can take you to other websites or different parts of the same page, making websites more interactive.
Approach
It's important to note that a link doesn't have to be just text. it can also be an image or any other thing you see on a webpage.
When you see links in a browser, they often have different looks:
- A link you haven't clicked yet is usually blue and underlined.
- If you've already clicked on a link, it might be purple and underlined.
- Sometimes, when you're clicking on a link, it might briefly turn red and underlined to show it's active.
- We will going to create link of all types.
Syntax:
<a href="url">link text</a>
target Attribute
- `_blank`: This makes the linked document open in a new window or tab.
- `_self`: It opens the linked document in the same window or tab as the link. This is the default behavior.
- `_parent`: If your webpage has frames, this option opens the linked document in the parent frame.
- `_top`: It opens the linked document in the whole window, replacing all frames.
- `framename`: If you have named a frame in your HTML, you can specify it here, and the linked document will open in that frame.
Example: This example demonstrates different target attributes for links, allowing them to open in various contexts such as new windows, the same window, parent frames, or specific frames within a page.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width,
initial-scale=1.0">
<title>Target Attribute Example</title>
</head>
<body>
<a href="https://www.geeksforgeeks.org" target="_blank">
Open GeeksforGeeks in a new window or tab</a>
<br>
<a href="https://www.geeksforgeeks.org" target="_self">
Open GeeksforGeeks in the same window or tab</a>
<br>
<a href="https://www.geeksforgeeks.org" target="_parent">
Open GeeksforGeeks in the parent frame</a>
<br>
<a href="https://www.geeksforgeeks.org" target="_top">
Open GeeksforGeeks in the full body of the window</a>
<br>
<!-- Assuming there's a frame named 'myFrame' -->
<a href="https://www.geeksforgeeks.org" target="myFrame">
Open GeeksforGeeks in 'myFrame'</a>
</body>
</html>
Output:
Output
Similar Reads
How To Link Two Pages In HTML ? The linking of two pages in HTML is a fundamental aspect of web development, used in over 95% of websites for navigation. The most common method is through the <a> (anchor) tag, which creates hyperlinks to other pages or resources. In this article, we will explore various ways to link pages in
3 min read
How To Link Pages In HTML? In HTML, linking pages is the fundamental practice that allows users to navigate from one web page to the another within same website or to an entirely different website. These links, also known as hyperlinks, are created using the <a> tag, which can direct the users to another HTML document,
5 min read
How to use anchor tag to open links in HTML ? In this article, we will learn how to use anchor tags to open links in HTML and we will implement different operations using anchor tags in HTML. We will see in this article, how to redirect another website through an anchor tag and how to open a blank new tag for any new link to open an image in a
3 min read
How to Create a Link to Send Email in HTML ? Incorporating email links into HTML pages facilitates a smooth way for users to send a message directly from the webpage. We will see how to create these email links, making your web pages user-friendly and interactive.Using Mailto Protocol with Predefined SubjectTo create a link to send an email in
2 min read
How to Link a Button to Another Page in HTML? Linking a button to another page is a common requirement in web development. It can allow the users to navigate between a website's different sections or pages. This can be done using the various HTML elements.PrerequisitesHTMLCSS1. Using <a> Tag Styled as ButtonThe <a> tag is traditiona
3 min read