tadam logo

HTML <a> Tag

Example

A link to Xhtml.co.il:
<a href="http://Xhtml.co.il/en/">This is a link</a>
The output of the code above will be:

Definition and Usage

The <a> tag defines an anchor. An anchor can be used in two ways:

  1. To create a link to another document, by using the href attribute
  2. To create a bookmark inside a document, by using the name attribute

The a element is usually referred to as a link or a hyperlink.

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

Browser Support

The <a> tag is supported in all major browsers.

Differences Between HTML and XHTML

NONE

Tips and Notes

Tip: Use CSS to style links!

Optional Attributes

DTD indicates in which HTML 4.01/XHTML 1.0 DTD the attribute is allowed. S=Strict, T=Transitional, and F=Frameset.

AttributeValueDescriptionDTD
charsetchar_encodingSpecifies the character-set of a linked documentSTF
coordscoordinatesSpecifies the coordinates of a linkSTF
hrefURLSpecifies the destination of a linkSTF
hreflanglanguage_codeSpecifies the language of a linked documentSTF
namesection_nameSpecifies the name of an anchorSTF
reltextSpecifies the relationship between the current document and the linked documentSTF
revtextSpecifies the relationship between the linked document and the current documentSTF
shapedefault
rect
circle
poly
Specifies the shape of a linkSTF
target_blank
_parent
_self
_top
framename
Specifies where to open the linked documentTF

Standard Attributes

The tag supports the following standard attributes:

AttributeValueDescriptionDTD
accesskeycharacterSpecifies a keyboard shortcut to access an elementSTF
classclassnameSpecifies a classname for an elementSTF
dirrtl
ltr
Specifies the text direction for the content in an elementSTF
ididSpecifies a unique id for an elementSTF
langlanguage_codeSpecifies a language code for the content in an elementSTF
stylestyle_definitionSpecifies an inline style for an elementSTF
tabindexnumberSpecifies the tab order of an elementSTF
titletextSpecifies extra information about an elementSTF
xml:langlanguage_codeSpecifies a language code for the content in an element, in XHTML documentsSTF

More information about Standard Attributes.

Event Attributes

The tag supports the following event attributes:

AttributeValueDescriptionDTD
onblurscriptScript to be run when an element loses focusSTF
onclickscriptScript to be run on a mouse clickSTF
ondblclickscriptScript to be run on a mouse double-clickSTF
onfocusscriptScript to be run when an element gets focusSTF
onmousedownscriptScript to be run when mouse button is pressedSTF
onmousemovescriptScript to be run when mouse pointer movesSTF
onmouseoutscriptScript to be run when mouse pointer moves out of an elementSTF
onmouseoverscriptScript to be run when mouse pointer moves over an elementSTF
onmouseupscriptScript to be run when mouse button is releasedSTF
onkeydownscriptScript to be run when a key is pressedSTF
onkeypressscriptScript to be run when a key is pressed and releasedSTF
onkeyupscriptScript to be run when a key is releasedSTF

Try it Yourself - Examples

Create hyperlinks
How to create hyperlinks.

Open a link in a new browser window
How to use an image as a link.

Open a link in a new browser window
How to open a link in a new browser window, so that the visitor does not have to leave your Web site.

The name attribute specifies the name of an anchor:
How to link to a bookmark.

Break out of a frame
How to break out of a frame (if your site is locked in a frame).

Create a mailto link
How to link to a mail message (will only work if you have mail installed).

Create a mailto link 2
Another mailto link.

Was this information helpful?
   

Comments