HOME C C++ PYTHON JAVA HTML CSS JAVASCRIPT BOOTSTRAP JQUERY REACT PHP SQL AJAX JSON DATA SCIENCE AI

HTML Links

In HTML, the <a> (anchor) element is used to create links or hyperlinks.

A hyperlink is a reference to another document, resource, or location on the web.

When a user clicks on a hyperlink, it typically navigates them to the linked destination.

Here's the basic syntax of an HTML link:

Example

             
<a href="url"> link text </a>  
You can click on above box to edit the code and run again.

Output

HTML Links - 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.

The target attribute specifies where to open the linked document.

The target attribute can have one of the following values:

  • _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

Example

<a href="https://www.w3schools.com/"> target="_blank">Visit CodeLines!
You can click on above box to edit the code and run again.

Output

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):

Example

            
<a href="mailto:someone@example.com">Send email</a>
You can click on above box to edit the code and run again.

Output

Linking with an Image:

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

Example

            
<a href="https://www.codelines.in">
<img src="codelines.jpg" alt"codeline image">
</a>
You can click on above box to edit the code and run again.

Output

Button as a Link

To use an HTML button as a link, you have to add some JavaScript code.

JavaScript allows you to specify what happens at certain events, such as a click of a button:

Example

            
<button onclick="document.location='default.asp'">HTML Tutorial</button>
You can click on above box to edit the code and run again.

Output