Toggle HTML CSS JavaScript

HTML Links


Links are found in nearly all web pages. Links allow users to click their way from page to page.


Note: A link does not have to be text. A link can be an image or any other HTML element!




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 (without the "https://www" part):

Example:

<h2>Absolute URLs</h2>
<a href="https://www.isro.gov.in/"> Indian Space Research Organization </a>

<h2>Relative URLs</h2>
<a href="index.html">Indian Space Research Organization </a>

Use a full URL to link a web page:

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

Link to a Page located in the html folder on the current web site:

<a href="/folder/file.html">HTML Tutorials</a>

Link to a page located in the same folder as the current page:

<a href="file.html">www.google.com</a>

Note: You can read more about file paths in the chapter HTML File Paths




Tip:Learn more about JavaScript in our JavaScript Tutorial.



Chapter Summary

  • Use the <a> element to define a link
  • Use the href attribute to define the link address.
  • Use the target attribute to define where to open the linked document
  • Use the <img> element (inside <a>) to use an image as a link
  • Use the mailto: scheme inside the href attribute to create a link that opens the user's email program