Loading...
Loading...
00:00:00

<a> Tag : Create Link in Webpage

The <a> tag, also known as the anchor tag, is one of the most commonly used HTML elements. It is used to create a hyperlink, which allows users to navigate to another page, a different section of the same page, or an external website, when clicked.

Here's an example of how you can create a hyperlink to Google using the <a> tag:

<a href="https://www.google.com">Go to Google</a>

The href attribute is used to specify the destination of the hyperlink. In this case, it's set to "https://www.google.com", which is the URL of the Google website. The text between the opening and closing <a> tags is the text that will be displayed as a clickable link.

Id with anchor tag

You can also create hyperlinks to other sections within the same page using the <a> tag and the id attribute. For example, let's say you have a heading on your page with the text "Introduction". To create a hyperlink to this heading, you can add an id attribute to the heading with a unique value:

<h2 id="introduction">Introduction</h2>

And then, you can create a hyperlink to this heading using the <a> tag and the href attribute, like this:

<a href="#introduction">Go to Introduction</a>

Notice that the href attribute in this case starts with a # symbol, followed by the value of the id attribute that you added to the heading. This tells the browser that you want to link to a specific section within the same page, rather than an external page.

In addition to linking to other pages or sections, the <a> tag can also be used to link to email addresses, telephone numbers, and other types of resources. For example, you can create a hyperlink to an email address like this:

<a href="mailto:example@email.com">Send an email</a>

And you can create a hyperlink to a telephone number like this:

<a href="tel:+1234567890">Call us</a>

The <a> tag also supports several attributes, such as target, rel, and title, that allow you to further customize the behavior and appearance of your hyperlinks.

The target attribute is used to specify where the linked page should be opened. For example, you can open the linked page in a new tab or window by setting the target attribute to _blank:

<a href="https://www.google.com" target="_blank">Go to Google</a>

The rel attribute is used to specify the relationship between the current page and the linked page. For example, you can indicate that the linked page is a sponsored advertisement by setting the rel attribute to sponsored:

<a href="https://www.google.com" rel="sponsored">Go to Google</a>

anchor Tag Attribues

The <a> tag, or anchor tag, supports several attributes that can be used to modify the behavior and appearance of a hyperlink. Some of the most commonly used <a> tag attributes are:

  1. href: Specifies the URL of the linked page. This attribute is required for creating a hyperlink.

  2. target: Specifies where the linked page should be opened. Common values for the target attribute include _blank (to open the linked page in a new tab or window), _self (to open the linked page in the same tab or window), and _parent (to open the linked page in the parent frame).

  3. rel: Specifies the relationship between the current page and the linked page. Common values for the rel attribute include nofollow (to indicate that the linked page should not be followed by search engines), sponsored (to indicate that the linked page is a sponsored advertisement), and alternate (to indicate that the linked page is an alternative version of the current page).

  4. hreflang: Specifies the language of the linked page. This attribute is used by search engines to understand the language of the linked page and to serve the correct version to users based on their language preferences.

  5. download: Specifies that the linked resource should be downloaded rather than navigating to it. This attribute is used to allow users to download files such as PDFs, images, and videos.

  6. title: Specifies additional information about the hyperlink, which will be displayed as a tooltip when the mouse pointer hovers over the link.

  7. ping: Specifies a list of URLs that will be notified when the link is clicked. This attribute is used for tracking and analytics purposes.

  8. type: Specifies the MIME type of the linked resource. This attribute is used to indicate the type of content that will be served when the link is clicked.

These are just a few of the most commonly used <a> tag attributes. Depending on your use case, there may be other attributes that you can use to further customize the behavior and appearance of your hyperlinks.