MOCKSTACKS
EN
Questions And Answers

More Tutorials









HTML Links

To make a hyperlink in an HTML page, use the <a> and </a> tags, which are the tags used to define the links. The <a>tag indicates where the hyperlink starts and the </a> tag indicates where it ends. Whatever text gets added inside these tags, will work as a hyperlink :

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.

 <a href ="url"> link text </a>

Example

 <a href ="https://google.com"> Go to the google </a>

example result



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

 <a href="https://www.google.com" target ="_self"> visit Google!  </a> 
 <a href="https://www.google.com" target ="_blank"> visit Google!  </a> 
 <a href="https://www.google.com" target ="_parent"> visit Google!  </a> 
 <a href="https://www.google.com" target ="_top"> visit Google!  </a> 



Absolute URLs vs. Relative URLs

Both examples above are using an absolute URL (a full web address) in the href attribute.

A local link (a link to a page within the same website) is specified with a relative URL:

Absolute URL :
 <a href="https://www.google.com"> Google </a> 

Relative URL :
 <a href="new/index.html"> index file </a> 


Image as a Link

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

Image Link:
 <a href="https://www.nature.com/"> 
    <img href="image-1.jpg" alt="Image 1">
 </a> 




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

Image Link:
 <a href="mailto:xyz123@gmail.com">Send Mail</a> 




Conclusion

In this page (written and validated by ) you learned about HTML Links . What's Next? If you are interested in completing HTML tutorial, your next topic will be learning about: HTML Link Color.



Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue: mockstacks@gmail.com.


Share On:


Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using Mockstacks.com, you agree to have read and accepted our terms of use, cookies and privacy policy.