Computer Study

HTML Anchor

HTML Anchor

An HTML anchor is a hyperlink that points to a specific location on a web page or to another web page. Anchors are created using the <a> tag, and can be used to link to other web pages, files, email addresses, or specific locations on a web page.

To create an anchor, you need to specify the URL or the location that the anchor should point to using the href attribute. Here’s an example of a basic anchor tag:

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

In this example, the href attribute specifies the URL that the anchor should point to, and the anchor text is “Link to Example”. When a user clicks on the link, they will be taken to the URL specified in the href attribute.

Anchors can also be used to link to specific locations on a web page, known as “anchors” or “bookmarks”. To do this, you need to add an id attribute to the element that you want to link to, and then use that ID in the href attribute of the anchor. Here’s an example:

<h2 id=”section1″>Section 1</h2>
<p>This is some text in section 1.</p>
<a href=”#section1″>Go to Section 1</a>

In this example, the <h2> element has an id attribute of “section1”, which creates an anchor point at that location. The anchor tag at the bottom of the example uses the href attribute to link to that anchor point, so when a user clicks on the link, they will be taken to the “Section 1” heading on the same page.

Anchors are a fundamental part of HTML and are used extensively in web pages to link to other content and to provide navigation within a website.

Appearance of HTML anchor tag

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

Link using target attribute

The target attribute in HTML is used to specify where the linked document should be opened when a user clicks on a link. It can be used with the <a> tag to open the linked document in a new window or tab, or to load it in a specific frame or iframe.

The target attribute takes several values, including:

  • _self: This is the default value, and it opens the linked document in the same window or tab as the current document.
  • _blank: This value opens the linked document in a new window or tab.
  • _parent: This value opens the linked document in the parent frame of a nested frameset.
  • _top: This value opens the linked document in the top-level browsing context (i.e., the full window or tab).

Here’s an example of an anchor tag with the target attribute set to _blank, which will open the linked document in a new window or tab:

<a href=”https://www.example.com” target=”_blank”>Link to Example</a>

In this example, the href attribute specifies the URL that the anchor should point to, and the target attribute is set to _blank. When a user clicks on the link, a new window or tab will open and display the linked document.

It’s important to note that opening linked documents in a new window or tab can be disruptive to the user’s browsing experience, so it should be used judiciously and with consideration for the user. Additionally, some browsers and browser plugins may block the ability to open links in new windows or tabs for security reasons.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button