HTML links tutorial

How to use html links

In this tutorial you will learn how HTML links works & more.

What is HTML link?

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: A link does not have to be text. It can be an image or any other HTML element.


Syntax

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

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

Live preview:

        
            
    <a href="https://mdbootstrap.com/">Visit our HomePage</a>
    
        
    

The href attribute specifies the destination address (https://mdbootstrap.com/) of the link.

The link text is the visible part (Visit our HomePage).

Clicking on the link text will send you to the specified address.



The 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

This example will open the linked document in a new browser window/tab:

        
            
    <a href="https://mdbootstrap.com/" target="_blank">Visit MDBootstrap</a>
    
        
    


Create a 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.

Example

First, create a bookmark with the id attribute:

        
            
    <h2 id="C4">Chapter 4</h2>
    
        
    

Then, add a link to the bookmark ("Jump to Chapter 4"), from within the same page:

        
            
    <a href="#C4">Jump to Chapter 4</a>