Skip to main content

How do you specify a link in the <a> tag?

The link is specified in the href attribute of the <a> tag. This attribute tells the browser where to go on click.

Usage examples

  1. A link to an external site:
html
<a href="https://example.com">Go to the site</a>

Here "https://example.com": the address of the page the link points to. 2. A link to an internal page of the site:

html
<a href="about.html">About us</a>

This link opens the about.html file located in the same folder. 3. A link to an anchor (part of the page):

html
<a href="#contact">Contacts</a> ... <div id="contact">Contacts section</div>

On click, the browser scrolls the page to the element with id="contact". 4. A link to download a file:

html
<a href="docs/manual.pdf" download>Download the manual</a>
  1. A link that opens in a new tab:
html
<a href="https://example.com" target="_blank">Open in a new tab</a>

Summary

To specify a link in the <a> tag, add the href attribute and put the address (URL) in quotes, for example:

html
<a href="https://example.com">Link text</a>

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.

How do you specify a link in the <a> tag?: HTML Interview Question