Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

HTML <a> Tag


Example

Create a link to W3Schools.com:

<a href="https://www.w3schools.com">Visit W3Schools.com!</a>
Try it Yourself »

More "Try it Yourself" examples below.


Definition and Usage

The <a> tag defines a hyperlink, which is used to link from one page to another.

The most important attribute of the <a> element is the href attribute, which indicates the link's destination.

By default, links will appear as follows in all browsers:

  • An unvisited link is underlined and blue
  • A visited link is underlined and purple
  • An active link is underlined and red

Tips and Notes

Tip: If the <a> tag has no href attribute, it is only a placeholder for a hyperlink.

Tip: A linked page is normally displayed in the current browser window, unless you specify another target.

Tip: Use CSS to style links: CSS Links and CSS Buttons.


Browser Support

Element
<a> Yes Yes Yes Yes Yes

Attributes

Attribute Value Description
download filename Specifies that the target will be downloaded when a user clicks on the hyperlink
href URL Specifies the URL of the page the link goes to
hreflang language_code Specifies the language of the linked document
media media_query Specifies what media/device the linked document is optimized for
ping list_of_URLs Specifies a space-separated list of URLs to which, when the link is followed, post requests with the body ping will be sent by the browser (in the background). Typically used for tracking.
referrerpolicy no-referrer
no-referrer-when-downgrade
origin
origin-when-cross-origin
same-origin
strict-origin-when-cross-origin
unsafe-url
Specifies which referrer information to send with the link
rel alternate
author
bookmark
external
help
license
next
nofollow
noreferrer
noopener
prev
search
tag
Specifies the relationship between the current document and the linked document
target _blank
_parent
_self
_top
Specifies where to open the linked document
type media_type Specifies the media type of the linked document

Global Attributes

The <a> tag also supports the Global Attributes in HTML.


Event Attributes

The <a> tag also supports the Event Attributes in HTML.



More Examples

Example

How to use an image as a link:

<a href="https://www.w3schools.com">
<img border="0" alt="W3Schools" src="logo_w3s.gif" width="100" height="100">
</a>
Try it Yourself »

Example

How to open a link in a new browser window:

<a href="https://www.w3schools.com" target="_blank">Visit W3Schools.com!</a>
Try it Yourself »

Example

How to link to an email address:

<a href="mailto:someone@example.com">Send email</a>
Try it Yourself »

Example

How to link to a phone number:

<a href="tel:+4733378901">+47 333 78 901</a>
Try it Yourself »

Example

How to link to another section on the same page:

<a href="#section2">Go to Section 2</a>
Try it Yourself »

Example

How to link to a JavaScript:

<a href="javascript:alert('Hello World!');">Execute JavaScript</a>
Try it Yourself »

Related Pages

HTML tutorial: HTML Links

HTML DOM reference: Anchor Object

CSS Tutorial: Styling Links


Default CSS Settings

Most browsers will display the <a> element with the following default values:

a:link, a:visited {
  color: (internal value);
  text-decoration: underline;
  cursor: auto;
}

a:link:active, a:visited:active {
  color: (internal value);
}


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.