You are here: Reference > HTML > tags > a

a element

Browser support:
Defines a link to the same or to another document, or defines a destination anchor.
The a (anchor) tag is one of the most useful HTML elements.
You can define a destination anchor with the name or a source anchor with the href attribute of the a element. A source anchor can refer to a document, a file or a destination anchor, or it can open the email client of the user, or it can execute a JavaScript code.
The following table contains protocols that can be used in the value of the href attribute.
Commonly used protocols:
  • Inner links:
    The inner links are useful to create a destination point where the browser may jump directly (scrolling the target to the top of the page if possible). The target must be an anchor tag with the name attribute specified, and if you want to jump to this point, you must only insert the value of the name attribute after a # (hash mark) sign in the href attribute of the source anchor or area element, as shown in Example 2.
  • http, https:
    Link to an external webpage, as shown in Example 1.
  • ftp:
    Opens a file transfer session (an FTP site), with or without a username and password, as shown in Example 4.
  • file:
    Allows downloading a file from the specified location. Because of security restrictions, most browsers allow downloading files only from the same domain where the original document is placed.
  • javascript:
    Allows the execution of JavaScript code, as shown in Example 5.
  • mailto:
    Opens the 'new message' dialog of user's default e-mail application with the specified e-mail address as the recipient, as shown in Example 3.
If you want to see the HTML tags by categories, please visit this page.
This element requires a closing tag.
JavaScript page for this element: a.

Possible members:

Attributes
Events
Styles
Pseudos
accessKey
Sets an access key to an element.
charset
Sets the character encoding of the document, a linked document or a script block.
class
Sets the style class or classes that belong to the element.
contentEditable
3
Sets whether the contents of the object are editable.
coords
Sets the position of a shape. You can select the type of shape with the shape attribute.
dataFld
Specifies which field of a given data source should be bound to the specified object.
dataSrc
Sets the identifier of the data source that is bound to the element.
dir
Sets the text direction as related to the lang attribute.
DISABLED
Sets the state of an object for user interaction.
draggable
3.55
Sets whether an element is draggable.
HIDEFOCUS
Specifies whether a dotted rectangle (focus rectangle) is drawn around an object while it has focus.
href
Specifies the location of the destination.
hrefLang
Sets the language of a linked resource or anchor element.
id
Sets a unique identifier for the object.
lang
Specifies the language of the element.
language
Sets the scripting language for the current element. Use it only for the script element.
methods
Specifies a comma-separated list of HTTP METHODS supported by the object and accessible to the user.
name
Sets the name of a target anchor.
rel
Specifies the relationship between the current document and the destination of an anchor or link.
rev
Specifies a reverse relationship from an anchor or link to the current document.
shape
Sets the shape type of the selectable region for a hypertext or an area.
spellcheck
Sets whether the automatic spellchecker is enabled.
style
Sets an inline style associated with an element.
tabIndex
Specifies the tabbing order for keyboard navigation using the TAB key.
target
Specifies the target window or frame where the document is to be opened.
title
Specifies a tooltip for an element.
type
Specifies the content type (MIME type) of the object or the linked object.
unSelectable
Sets whether the selection process can start in an element's content.
urn
Specifies a Uniform Resource Name (URN) for a linked object.
xml:lang
Sets the language code of the XML document.

Example HTML code 1:

This example shows how to create an external link:
<a href="http://www.example.com/" target="_blank">External Link</a>
Did you find this example helpful? yes no

Example HTML code 2:

This example shows how to jump to a destination anchor on the current page:
<a href="#to">External Link</a>

<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />

<h1 id="to">The goal of the jump</h1>
Did you find this example helpful? yes no

Example HTML code 3:

This example shows how to send mail with the anchor tag:
<a href="mailto:support@example.com">Send mail</a>
Did you find this example helpful? yes no

Example HTML code 4:

This example shows how to create a link to a protected ftp:
<a href="ftp://user:secretpassword@example.com/path/file">FTP with password</a>
Did you find this example helpful? yes no

Example HTML code 5:

This example shows how to execute JavaScript code from a href attribute:
<a href="javascript: alert ('You clicked the link.')">Execute JavaScript</a>
Did you find this example helpful? yes no

Related pages:

External links:

User Contributed Comments

Post Content

Post Content