How To Add Hyperlinks in HTML

Hyperlinks can be added to text or images with the anchor link element <a>. The <a> tag requires the attribute href, which is used to specify the destination link. The <a> element is used like this:

<a href="www.DestinationLink.com">The text you want to link</a> 

Try adding the code snippet below to your “index.html” file and changing the sample highlighted text with a real link, such as https://digitalocean.com/community:

<a href="https://www.digitalocean.com/community">The text you want to link</a> 

(If you have not been following the tutorial series, you can review instructions for setting up an index.html file in our tutorial Setting Up Your HTML Project. Save the file and load it in your browser.

You should receive an output like this:

HTML Link

You can also link images by wrapping an image element with an <a> element like so:

<a href="https://www.digitalocean.com/community">The text you want to link <img src="https://html.sammy-codes.com/images/small-profile.jpeg"> </a> 

Try testing the code snippet in your browser to check that it works. You should now understand how to add hyperlinks to text and images on your webpage.