How to use a href in HTML to add links to your website

a href is used to include external and internal links on a website. The authorized values for the HTML attribute href are clearly defined. These include links to other websites and forwarding to email addresses or telephone numbers.

What is href and what is it used for?

a href allows users to create external or internal links in an HTML document. When used correctly, the href attribute integrates seamlessly into a website and appears in the form of a hyperlink. This allows visitors to click and visit another page on your site. The term href stands for “hyper reference” and specifies the desired link destination.

href attributes offer your website numerous advantages. They provide a better structure, facilitate navigation, and provide additional information. Links can also be beneficial for SEO. According to Google, it doesn’t matter whether you use an absolute URL, which includes the domain name, or a relative URL without a preceding domain name.

To display this video, third-party cookies are required. You can access and change your cookie settings here.

What is the structure of a href?

The syntax for href is always the same in HTML and looks like this:

<a href="URL">anchor text</a>

Each section fulfils an important function:

  • The a introduces the link and indicates an anchor text. This HTML tag defines the start and end point of the hyperlink.
  • The href attribute is used within the anchor text and sets the respective link’s jump target. In addition to an internal or external website, PDF documents or images can also be linked.
  • The URL for the link is placed within the quotation marks.
  • This is followed by the visible text, which is clickable.
  • The anchor text is complete.

Often links are combined with the title attribute to define the link title, an alternative description of the link target. The link title can contain additional information about the linked website. It becomes visible in the frontend when you hover over the link without clicking on it. Defining link titles is also recommended as an SEO measure. In HTML it looks like this:

<a href="URL" title="Linktitle">anchor text</a>

What values can href have?

The values for href in HTML are clearly defined to ensure that linking works properly. The authorized values for href are as follows:

  • An absolute URL: When using a href, the absolute URL is the classic example. It redirects directly to an external website and contains the domain name, the path and (if available) the file name. Example: <a href="">Absolute link to the example page</a>
  • A relative URL: In a relative URL, you only specify the path (the file name is optional). For this reason, relative URLs are much shorter than absolute ones. Example: <a href="/topic/index.html">Relative link to example page</a>
  • Link to an element: The direct link to an element is possible if it has a defined ID. This allows you to internally link different sections of your website. Example: <a href="#section3">Direct link to an element</a>
  • Other protocols: href is also suitable for other protocols, such as linking directly to an email address. This works via mailto:. Other protocols may include https://, ftp://, or file:.
  • Scripts: Scripts, such as JavaScript, are also authorized values for a href. Example: href="javascript:alert('Do you have any further questions?');">

Find out how to embed JavaScript in HTML in our Digital Guide.

Five examples for how to use a href

You can use a href for different purposes. Below we’ll show you some of the most common use cases for href in HTML.

Use the following code to set an image as a link to a subpage:

<a href=""><img src=" /exampleimage.jpg" alt="image description"></a>

Use mailto: to link an email address:

<a href=""></a>

The visitor’s email client will open when they click the link and the address ( will automatically be inserted as the recipient. Alternatively, they can also copy and paste the email address into the program or to another location.

You can also link a phone number with a href. This is useful if someone accesses your site using a smartphone and wants to contact you directly. The link looks like this:

<a href="tel:+11231234567">0123 1234567</a>

It is important to add a plus sign and the international dialing code after the telephone reference tel:. The zero in the area code is not included.

You can also link to JavaScript using href. The corresponding code is:

<a href="javascript:Example ( )">example</a>

While links are useful, be careful not to send your visitors to an external site directly from your website. With this in mind, it is useful for the link to open in a new tab or a new window. Users will then remain on your site and can look at any additional information at another time. The code for opening a link in a new tab or window looks like this:

<a href="" target="_blank"></a>

Create your perfect website in just a few steps! The Website Builder from IONOS offers useful tools that are easy to manage, allowing you to easily create a professional online presence. If you would rather leave it up to our experts, they can take over the design for you and build a website according to your individual requirements. Choose a solution that fits your needs.

We use cookies on our website to provide you with the best possible user experience. By continuing to use our website or services, you agree to their use. More Information.
Page top