Home >Web Front-end >HTML Tutorial >Anchor in HTML

Anchor in HTML

王林
王林Original
2024-09-04 16:38:46449browse

HTML anchor tag is one of the most important elements in HTML used for navigating between websites, moving from one page to another, mouse click to open some kind of image or text. It’s used to define the starting and end of the included hyperlink. Mostly this is used by the search engine to define destination URL. It’s informative and works as more relevant to the landing page.

Those links represent different meanings in a different scenario like

  • Link with underline and red in color shows an active link
  • Link with underline and purple in color shows visited link.
  • Link with underline and blue in color shows an unvisited link.

Syntax:

Let’s see actual syntax for defining tag.

<a href="Link_URL">Link Home</a>

As shown above, syntax tag containing a link with major parts as defined below:

Anchor in HTML

1. href attribute

This attribute is used to define hyperlink, in which one may familiar with its destination address. Hyperlink work as a connector in between your web page document and target link.

  2. Name attribute

The name attribute in tag is used to go at a specific point to the page.

  3. Target attribute

  • The target attribute is used to define the destination page or the defined target page may be opened.
  • It’s used as a common option that is used by target attributes to link with other pages.
  • If the target attribute defines with a blank value like “target=_blank” then it will open a new tab at the target location.

4. Title Attribute

  • The title attribute is one of the important attributes used to give special attention where one can easily move when they click the link.
  • If the user moves the mouse pointer onto the link reference, the title text which was given into the attribute point will be shown there.
  • It works like a tooltip or details where the link will navigate. This approach makes webpages or documents more user-friendly.

Working of Anchor in HTML

Examples

Here we are going to show some examples having use of actual tag.

1. HTML code

<h4>Examples for Anchor in HTML </h4>
<a href="https://timesofindia.indiatimes.com/">Latest News </a><br><br>
<a href="HTMLcolor.html">Navigate on other File</a><br>

Output:
 Anchor in HTML

On clicking the latest news, the output is :Anchor in HTML

 By clicking on the link Navigate on other File” it will show another webpage as:
Anchor in HTML

2. HTML Code

<h2>Reach to EDUCBA </h2>
<ul>
<li><a href="https://www.educba.com/">Website</a></li>
<li><a href="mailto:[email&#160;protected]">Email US</a></li>
<li><a href="tel:+123456789">Phone</a></li>
</ul>

 Output :

Anchor in HTML

The output shows some links, and that those links are in blue they are unvisited, the link showing in purple has visited the link and this is used to show the difference in links.

3. HTML Code

<h4>Image and File Demo</h4>
<p><a href="C:\Users\\Sonali\Desktop\jerry.jpeg">Image Demo</a> It will
open image</p>
<a href="./generate-zip?id=4" download="assets.zip">Download File</a>

Output :

Anchor in HTML

While clicking on image demo it will open the image as:Anchor in HTML

 While clicking on another link it will download the file as :Anchor in HTML

Conclusion- Anchor in HTML

Anchor tag in HTML is used to define a link that will navigate directly to the target location. It’s based on major components like hre attribute, name attribute, target attribute. tag is used for the internal and external links as well as for absolute and relative URL.

The above is the detailed content of Anchor in HTML. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Dropdown List in HTMLNext article:Dropdown List in HTML