The <a href> attribute refers to a destination provided by a link. The a (anchor) tag is dead without the <href> attribute.

How to use the <a href> tag

Sometimes in your workflow, you don’t want a live link or you won’t know the link destination yet. In this case, it’s useful to set the href attribute to "#" to create a dead link.

The href attribute can be used to link to local files or files on the internet.

For instance:

    <title>Href Attribute Example</title>
    <h1>Href Attribute Example</h1>
        <a href="">The freeCodeCamp Contribution Page</a> shows you how and where you can contribute to freeCodeCamp's community and growth.

The <a href> attribute is supported by all browsers.

More HTML attributes:

hreflang : Specifies the language of the linked resource.

target : Specifies the context in which the linked resource will open.

title : Defines the title of a link, which appears to the user as a tooltip.


<a href="#">This is a dead link</a>
<a href="">This is a live link to freeCodeCamp</a>
<a href="">more with a href attribute</a>

In-page anchors

It’s also possible to set an anchor to certain place of the page. To do this you should first place a tab at location on the page with tag and necessary attribute “name” with any keyword description in it, like this:

<a name="top"></a>

Any description between tags is not required. After that you can place a link leading to this anchor at any palce on same page. To do this you should use tag with necessary attribute “href” with symbol # (sharp) and key-word description of the anchor, like this:

<a href="#top">Go to Top</a>

The <a href="#"> may also be applied to images and other HTML elements.


<a href="#"><img itemprop="image" style="height: 90px;" src="" alt="picture">  </a>

Some more examples of href

<base href="">This gives a base url for all further urls on the page</a>
<link href="style.css">This is a live link to an external stylesheet</a>

What else can you do with <a href>?

More customization! Let's see a specific use case:

A mailto link is a kind of hyperlink (<a href=""></a>) with special parameters that lets you specify additional recipients, a subject line, and/or a body text.

The basic syntax with a recipient is:

<a href="">Some text</a>

Adding a subject to that mail:

If you want to add a specific subject to that mail, be careful to add %20 or + everywhere there’s a space in the subject line. An easy way to ensure that it is properly formatted is to use a URL Decoder / Encoder.

Adding body text:

Similarly, you can add a specific message in the body portion of the email: Again, spaces have to be replaced by %20 or +. After the subject paramater, any additional parameter must be preceded by &

Example: Say you want users to send an email to their friends about their progress at Free Code Camp:

Address: empty

Subject: Great news

Body: I am becoming a developer

Your html link now:

<a href="mailto:?subject=Great%20news&body=I%20am%20becoming%20a%20developer">Send mail!</a>

Here, we’ve left mailto empty (mailto:?). This will open the user’s email client and the user will add the recipient address themselves.

Adding more recipients:

In the same manner, you can add CC and bcc parameters. Seperate each address by a comma!

Additional parameters must be preceded by &.

<a href=",">Send mail!</a>

More Information:

MDN - E-mail links