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

HTML Links Hyperlinks

Last Updated : 02 Dec, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

HTML Links, also known as hyperlinks, are defined by the <a> tag in HTML, which stands for “anchor.” These links are essential for navigating between web pages and directing users to different sites, documents, or sections within the same page.

The basic attributes of the <a> tag include href, title, and target, among others.

Basic Syntax of an HTML Link:

<a href="https://www.example.com">Visit Example</a>

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

A Simple HTML Link Example

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:

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.

HTML Links – Target Attribute

The target attribute in the <a> tag specifies where to open the linked document. It controls whether the link opens in the same window, a new window, or a specific frame.

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.

Example: 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: 

Linking Different HTML Elements

Below are examples of how to link different HTML elements with their respective code snippets

Element to InterlinkSpecific Code
Linking to an image <a href="image.jpg"><img src="image.jpg" alt="Image"></a>
Link to an Email Address<a href="mailto:someone@example.com">Send Email</a>
Phone Number<a href="tel:+1234567890">Call Now</a>
Button<a href="https://www.example.com"> <button>Visit Example</button> </a>
Link to Download File<a href="file.pdf" download>Download File</a>
Link Title<a href="https://www.example.com" title="Visit Example">Link Text</a>

Supported Browsers

HTML Links Hyperlinks – FAQs

What is an HTML hyperlink?

An HTML hyperlink is created using the <a> tag to link to other web pages, files, locations within the same page, email addresses, or any URL.

How to create a basic hyperlink in HTML?

Use the <a> tag with the href attribute. Example: <a href=”https://example.com”>Visit Example</a>

How to open a link in a new tab or window?

Add the target=”_blank” attribute to the <a> tag. Example: <a href=”https://example.com” target=”_blank”>Visit Example</a>

How to add link to an email address?

Use the mailto: scheme in the href attribute. Example: <a href=”mailto:someone@example.com”>Email Us</a>

Can hyperlinks be styled with CSS?

Yes, hyperlinks can be styled using CSS with pseudo-classes like :link, :visited, :hover, and :active. Example: a { color: green; } a:hover { color: blue; }



Next Article

Similar Reads

three90RightbarBannerImg