The Wayback Machine - https://web.archive.org/web/20240707231823/https://www.geeksforgeeks.org/html-links/
Open In App

HTML Links Hyperlinks

Last Updated : 27 Jun, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

HTML links, or hyperlinks, connect web pages and are created using the `<a>` tag with the `href` attribute. They enable users to navigate between pages or resources. Links can be text, images, or other elements, enhancing web navigation and interactivity. Users can click on links to navigate between different pages or resources.

Note: A hyperlink can be represented by an image or any other HTML element, not just text.

By default, links will appear as follows in all browsers:

  • An unvisited link is underlined and blue
  • A visited link is underlined and purple
  • An active link is underlined and red

Syntax

<a href="url">link text</a>

Target Attribute

AttributeDescription
_blankOpens the linked document in a new window or tab.
_selfOpens the linked document in the same frame or window as the link. (Default behavior)
_parentOpens the linked document in the parent frame.
_topOpens the linked document in the full body of the window.
framenameOpens the linked document in a specified frame. The frame’s name is specified in the attribute.

HTML Links Examples

Example 1: Basic Hyperlink

In this example we contains a paragraph instructing users to click on the link labeled “GeeksforGeeks,” which directs to the website “https://www.geeksforgeeks.org”.

HTML
<!DOCTYPE html>
<html>

<head>
    <title>HTML Links</title>
</head>

<body>
    <p>Click on the following link</p>
    <a href="https://www.geeksforgeeks.org">
        GeeksforGeeks
    </a>
</body>

</html>

Output:

HtmlLinks

HTML Links example output

Example 2: Using target Attributes

In this example we demonstrates the use of target attributes in links. Each link opens in a different context: _blank opens in a new window or tab, _self in the same frame, _parent in the parent frame, _top in the full window body, and framename in a specified frame.

HTML
<!DOCTYPE html>
<html>

<head>
    <title>Target Attribute Example</title>
</head>

<body>
    <h3>
        Various options available in the
        Target Attribute
    </h3>

    <p>
        If you set the target attribute to
        "_blank", the link will open in a new
        browser window or tab.
    </p>
    <a href="https://www.geeksforgeeks.org" 
       target="_blank">
        GeeksforGeeks
    </a>

    <p>
        If you set the target attribute to
        "_self", the link will open in the
        same window or tab.
    </p>
    <a href="https://www.geeksforgeeks.org" 
       target="_self">
        GeeksforGeeks
    </a>

    <p>
        If you set the target attribute to
        "_top", the link will open in the full
        body of the window.
    </p>
    <a href="https://www.geeksforgeeks.org" 
       target="_top">
        GeeksforGeeks
    </a>

    <p>
        If you set the target attribute to
        "_parent", the link will open in the
        parent frame.
    </p>
    <a href="https://www.geeksforgeeks.org" 
       target="_parent">
        GeeksforGeeks
    </a>
</body>

</html>

Output: 

linksOP2

Supported Browser


Previous Article
Next Article

Similar Reads

Difference between normal links and active links
Websites are designed to point you to different resources. You can move from one website to another through links. Links help you to get information from different resources. Links are established in simple HTML web pages through &lt;a&gt; tag.Links are categorized into three types. Typically a Link is displayed in three different colors based on t
2 min read
How to overrule underlining Hyperlinks ?
In CSS, the hyperlinks are underlined by default. This is due to the default decoration that is imposed by HTML/CSS. To get rid of this underline, we need to do the following changes in the default decoration of the anchor tag using CSS. We can get rid of underlying hyperlinks by using CSS text-decoration property. If this property is set to none t
1 min read
HTML DOM links Collection
The DOM links collection is used to return the collection of all &lt;a&gt; and &lt;area&gt; elements with the "href" attribute in the HTML document. The elements in the collection are sorted as they appear in the sourcecode. Syntax: document.links Properties: It contains a single property length which is used to return the number of &lt;a&gt; and
4 min read
How to disable HTML links using JavaScript / jQuery ?
Given an HTML link and the task is to disable the link by using JavaScript/jQuery. Approach 1: Disable HTML link using JavaScript using setAttribute() Method. JavaScript setAttribute() Method: This method adds the defined attribute to an element and gives it to the passed value. In case of the specified attribute already exists, the value is set/ch
5 min read
How to create Right Aligned Menu Links using HTML and CSS ?
The right-aligned menu links are used on many websites. Like hotels website that contains lots of options in the menu section but in case of emergency to make contact with them need specific attention. In that case, you can put all the menu options on the left side of the navigation bar and display contact us option on the right side of the bar. Th
3 min read
How to create animated banner links using HTML and CSS?
Links are one of the most important parts of any component that is used in website making. Almost every component had some form of links in it. A common example is a menu/nav-bar. All we see is some button like home, about, etc. but under the hood they all are links. Sometimes there comes a situation where you don't want to wrap the link inside a b
2 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 new tag, and how to open the image on the same pag
3 min read
How to Create Links to Other Pages in HTML ?
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
2 min read
How to Add Skip Navigation Links for Better Web Accessibility in HTML?
Adding skip navigation links in HTML is an essential practice for enhancing web accessibility. These links allow users to bypass repetitive navigation menus and directly access the main content of a webpage, especially for screen reader users or keyboard-only users. This simple addition significantly improves the usability and accessibility of a we
7 min read
How to Find & Add Nofollow Links to your Website in HTML ?
The nofollow attribute in links is a crucial tool for controlling how search engine crawlers interact with your website's content. By adding the nofollow attribute to specific links, you instruct search engine bots not to follow those links, preventing them from spreading content to linked pages. This helps control spam and can improve your website
2 min read
three90RightbarBannerImg