HTML / Element

The a Element (Links)

The HTML a element represents a link to another page, a place within a page, or another resource.

The answer first

An a element with an href attribute is a hyperlink that users can follow, such as this example.

An a element without href is not a link. It represents a placeholder for where a link might otherwise be placed.

Minimal example

<a href="https://example.com/">Visit Example</a>

The browser displays “Visit Example”. When the user follows it, the browser navigates to the URL in href.

What does href specify?

The href attribute specifies the destination URL. It can be an absolute URL, a relative URL on the same site, or a fragment that points to a place in the current document.

<a href="/yugien/en/form.html">Read about forms</a>
<a href="/atlas/en/form.html#fact-evidence">Go to specification evidence</a>
<a href="mailto:[email protected]">Send an email</a>

Choose between a link and a button

Use an a element to move somewhere. Use a button element to perform an action in the current page.

PurposeElement
Navigate to another page<a href="...">
Open a menu or perform an action on the current page<button type="button">
Submit a form<button type="submit">

A button does not need to be used as a substitute for a link just because it can be styled to look like one.

Common mistakes

  • Using href="#" only to attach a click handler when there is no destination
  • Using JavaScript alone for ordinary page navigation
  • Representing an action with a link instead of a button
  • Using vague link text such as “click here” without a clear destination

Going further

Attributes such as target, download, rel, and hreflang describe additional link behavior or relationships. Before adding one, identify whether the link is for navigation, downloading, or another purpose.

Check it in Atlas

For the conditions, content model, activation behavior, and DOM API behind the element, see the a element in Yugien Atlas. For button type states and form processing, see the button element in Atlas.