The a trong html w3schools


Example

Create a link to W3Schools.com:

Visit W3Schools.com!

Try it Yourself »

More "Try it Yourself" examples below.


Definition and Usage

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

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

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


Tips and Notes

Tip: If the 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
Yes Yes Yes Yes Yes

Attributes

AttributeValueDescription
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 tag also supports the Global Attributes in HTML.


Event Attributes

The tag also supports the Event Attributes in HTML.



More Examples

Example

How to use an image as a link:


The a trong html w3schools

Try it Yourself »

Example

How to open a link in a new browser window:

Visit W3Schools.com!

Try it Yourself »

Example

How to link to an email address:

Send email

Try it Yourself »

Example

How to link to a phone number:

+47 333 78 901

Try it Yourself »

Example

How to link to another section on the same page:

Go to Section 2

Try it Yourself »

Example

How to link to a JavaScript:

Execute JavaScript

Try it Yourself »


HTML tutorial: HTML Links

HTML DOM reference: Anchor Object

CSS Tutorial: Styling Links


Default CSS Settings

Most browsers will display the 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);
}


❮ HTML tag

Example

The href attribute specifies the link's destination:

Visit W3Schools

Try it Yourself »

More "Try it Yourself" examples below.


Definition and Usage

The href attribute specifies the URL of the page the link goes to.

If the href attribute is not present, the tag will not be a hyperlink.

Tip: You can use href="#top" or href="#" to link to the top of the current page!


Browser Support

Attribute
href Yes Yes Yes Yes Yes

Syntax

Attribute Values

ValueDescription
URL The URL of the link.

Possible values:

  • An absolute URL - points to another web site (like href="http://www.example.com/default.htm")
  • A relative URL - points to a file within a web site (like href="default.htm")
  • Link to an element with a specified id within the page (like href="#section2")
  • Other protocols (like https://, ftp://, mailto:, file:, etc..)
  • A script (like href="javascript:alert('Hello');")


More Examples

Example

How to use an image as a link:


The a trong html w3schools

Try it Yourself »

Example

How to link to an email address:

Send email

Try it Yourself »

Example

How to link to a phone number:

+47 333 78 901

Try it Yourself »

Example

How to link to another section on the same page:

Go to Section 2

Try it Yourself »

Example

How to link to a JavaScript:

Execute JavaScript

Try it Yourself »


❮ HTML tag