HTML links


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


Local Links

The example above used an absolute URL (a full web address).

A local link (link to the same web site) is specified with a relative URL (without https://www....).



                    <a href="images/photo-1.jpg">Link to the image</a>
                
                

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>
                  
                  

Live preview


Image as Link

It is common to use images as links:



                      <a href="https://mdbootstrap.com/" target="_blank"><img src="https://mdbootstrap.com/img/logo/mdb192x192.jpg"></a>
                  
                  

Live preview (click the image)


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>
               
               
Click to see the example

Rate this lesson

Previous lesson Next lesson

Spread the word:
Do you need help? Use our support forum

About the author

User avatar
Michal Szymanski
Co-Founder at MDBootstrap & BrandFlow. Entrepreneur, web developer, UI/UX designer, marketing analyst. Dancer and nerd in one.