HTML Links

Hyperlinks

HTML links are hyperlinks.

You can click on a link and jump to another document.

When you move the mouse over a link, the mouse arrow will turn into a little hand.

Note: HTML links are hyperlinks. You can click on a link and jump to another document. When you move the mouse over a link, the mouse arrow will turn into a little hand.


Syntax

In HTML, links are defined with the <a> tag.

HTML Code:

<a href="https://www.w3schools.com/html/">Visit a HTML tutorial</a>

Result:


Link Colors

By default, a link will appear like this (in all browsers):

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

You can change the default colors, by using styles.

CSS Code:

<style> .exlink a:link { color: green; background-color: transparent; text-decoration: none; } .exlink a:visited { color: pink; background-color: transparent; text-decoration: none; } .exlink a:hover { color: red; background-color: transparent; text-decoration: underline; } .exlink a:active { color: yellow; background-color: transparent; text-decoration: underline; } </style>

HTML Code:

<p>You can change the default colors of links</p> <p class="exlink"><a href="#" target="_blank">Example Link</a></p>

Result:

You can change the default colors of links


Target Attribute

The target attribute specifies where to open the linked document.

The target attribute can have one of the following values:

  • _blank - Opens the linked document in a new window or tab
  • _self - Opens the linked document in the same window/tab as it was clicked (this is default)
  • _parent - Opens the linked document in the parent frame
  • _top - Opens the linked document in the full body of the window
  • framename - Opens the linked document in a named frame

HTML Code:

<p><a href="https://www.w3schools.com/" target="_blank">Visit W3Schools! (_blank)</a></p> <p><a href="https://www.w3schools.com/" target="_self">Visit W3Schools! (_self)</a></p>

Result:


Image as Link

HTML Code:

<a href="https://www.w3schools.com/html" target="_blank"> <img src="html_symbol_01.jpg" alt="HTML tutorial" style="width:42px;height:42px;border:0;"> </a>

Result:


Bookmark

HTML bookmarks are used to allow readers to jump to specific parts of a Web page.

Bookmarks can be useful if your webpage is very long.

To make a bookmark, you must first create the bookmark, and then add a link to it.

When the link is clicked, the page will scroll to the location with the bookmark.

HTML Code:

<p><a href="#C4">Jump to Chapter 4</a></p> <h2>Chapter 1</h2> <p>This chapter explains ba bla bla</p> <h2>Chapter 2</h2> <p>This chapter explains ba bla bla</p> <h2>Chapter 3</h2> <p>This chapter explains ba bla bla</p> <h2 id="C4">Chapter 4</h2> <p>This chapter explains ba bla bla</p> <h2>Chapter 5</h2> <p>This chapter explains ba bla bla</p>

Result:

Jump to Chapter 4

Chapter 1

This chapter explains ba bla bla

Chapter 2

This chapter explains ba bla bla

Chapter 3

This chapter explains ba bla bla

Chapter 4

This chapter explains ba bla bla

Chapter 5

This chapter explains ba bla bla

HTML Index

References

  1. W3Schools

This page is only a summary of the material from W3Schools. Definitions, Examples and Codes are exclusive property of W3Schools.