HTML a Tag

  • HTML <a> tag defines an anchor link.

  • An anchor to create or set link either internally or externally. A link is a connection from one Web resource to another. Another way link is primary concept to drive one page to another page into a web.

  • User linked from text file, image file or any other resource files to current document using HREF attribute. and TITLE attribute use for provide a description of that location file, which are linked to current document.

  • The most required attribute of the <a> tag is the href attribute, which are indicates the link's destination.

  • HREF link will appear below:

    1. Unvisited link is blue with underline.

    2. Visited link is maroon with underline.

    3. Active link is green with underline.

Link open new window

<!DOCTYPE html>
<html>
<head>
  <title>HTML a tag</title> 
</head>
<body>
  Click Here to open 
  <a href="http://www.way2tutorial.com/" target="_blank">
    Way2Tutorial Web Development Tutorials
  </a>
</body>
</html>

Run it...   »

Image Link

<!DOCTYPE html>
<html>
<head>
    <title>HTML a tag</title>
</head>
<body>
    Click Here to open 
    <a href="http://www.way2tutorial.com/" target="_blank">
        <img src="../../images/w2t.png" width="380" height="70"/>
    </a>
</body>
</html>

Run it...   »

Internal Link

<!DOCTYPE html>
<html>
<head>
</head>
<body>
  <a href="#Lession.1">Lession.1</a><br />
  <a href="#Lession.2">Lession.2</a><br />
  <a href="#Lession.3">Lession.3</a><br />
  <a href="#Lession.4">Lession.4</a><br />
  <br />

  <a name="Lession.1">Introduction of Lession.1</a>
  <p>This is sub topic.1</p>
  <p>This is sub topic.2</p>
  <p>This is sub topic.3</p>
  <p>This is sub topic.4</p>
  <br />
  <br />
  <a name="Lession.2">Introduction of Lession.2</a>
  <p>This is sub topic.1</p>
  <p>This is sub topic.2</p>
  <p>This is sub topic.3</p>
  <p>This is sub topic.4</p>
  <br />
  <br />
  <a name="Lession.3">Introduction of Lession.3</a>
  <p>This is sub topic.1</p>
  <p>This is sub topic.2</p>
  <p>This is sub topic.3</p>
  <p>This is sub topic.4</p>
  <br />
  <br />
  <a name="Lession.4">Introduction of Lession.4</a>
  <p>This is sub topic.1</p>
  <p>This is sub topic.2</p>
  <p>This is sub topic.3</p>
  <p>This is sub topic.4</p>
</body>
</html>

Run it...   »

Mailto Link

<!DOCTYPE html>
<html>
<head>
</head>
<body>
  <p>
    <a href="mailto:[email protected][email protected]&[email protected]&subject=Feedback&body=Message">Click Here </a>
    for Feedback
  </p>
</body>
</html>

Run it...   »

<a> tag Attributes

<a> tag has support following specific attributes.

Attributes Value Description
href url Specifies the destination link document.
name internal_name Specifies the name of an anchor it's use in Internal Link.
rel text relationship between current document or linked document.
rev text relationship between linked document or current document.
target _blank
_parent
_self
_top
Loads the linked document in new window.
Loads the linked document in the parent frame.
Loads the linked document in the same window.
Loads the linked document in the top up on same window.

Global Attributes

<a> tag also support global attributes.

Attributes Value Description
id unique_name Declared unique id for an element.
class class_name Declared one or more classnames for an element.
style styles CSS inline styles specify an element.
title title Specify extra details of element contain, this will display as a "tooltip" for an elements.

Event Attributes

<a> tag support following Event attributes.

Attributes Value Description
onfocus script element gets focus on object when script tobe run.
onblur script element lose the focus on object when scrip tobe run.
onclick script clicked on object when script tobe run.
ondblclick script double click on object when script tobe run.
onkeydown script key is pressed when script tobe run.
onkeypress script key is pressed over element then released when script tobe run.
onkeyup script key is released over element when script tobe run.
onmousedown script mouse button was pressed over an element when script tobe run.
onmouseout script mouse pointer release over an element when script tobe run.
onmousemove script run mouse pointer moved when script tobe run.
onmouseover script run mouse pointer move over when script tobe run.
onmouseup script mouse button is released when script tobe run.

Browser Compatibility

  • Google Chrome
    Yes
  • Mozilla Firefox
    Yes
  • Microsoft Edge
    Yes
  • Opera
    Yes
  • Safari
    Yes