HTML Code For Links

Learn HTML code for links or link tutorial.


<!DOCTYPE html>
<html>
<body>

<a href="#">This is a link</a>

</body>
</html>

HTML Code Displays


This is a link

Replacing '#' with your page link.



The target Attribute

By default, the linked page will be displayed in the current browser window. To change this, you must specify another target for the link.

  • _self - Default. Opens the document in the same window/tab as it was clicked.
  • _blank - Opens the document in a new window or tab.
  • _parent - Opens the document in the parent frame.
  • _top - Opens the document in the full body of the window.

<!DOCTYPE html>
<html>
<body>

<a href="#" target="_blank">This is a link</a>

</body>
</html>



Use an Image as a Link

To use an image as a link, just put the 'img' tag inside the 'a' tag:


<!DOCTYPE html>
<html>
<body>

<a href="#">
<img src="image-path.gif" alt="HTML tutorial" style="width:50px;height:50px;">
</a>

</body>
</html>



Link to an Email Address

Use mailto: inside the href attribute to create a link that opens the user's email program (to let them send a new email):


<!DOCTYPE html>
<html>
<body>

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

</body>
</html>