57 out of 95 rated this helpful - Rate this topic

a element | a object

[This documentation is preliminary and is subject to change.]

Designates the start or destination of a hypertext link.

Document Object Model (DOM) Level 2 HTML Specification, Section 1.6.5HTML 4.01 Specification, Section 1

Standards information

HTML information

Closing Tagrequired
CSS Displayinline

Remarks

The a element requires the href or the name attribute to be specified.

Both text and images can be included within an anchor. An image that is an anchor has a border whose color indicates whether the link has been visited. To prevent this border from appearing, you can set the img element's border attribute to 0 or omit the border attribute. You can also use Cascading Style Sheets (CSS) attributes to override the default appearance of a and img elements.

Note  A table object does not function properly when contained within an a tag.

Windows Internet Explorer 8 and later. The value of the href attribute depends on the current document compatibility mode.

Internet Explorer 8 and later. When Protected Mode is enabled and a Web page contains an anchor link with a named target, Windows Internet Explorer opens the target of the link in a new window when the target has a different integrity level than the Web page containing the link. For more information, see Understanding and Working in Protected Mode Internet Explorer.

Examples

The following examples use the a element to link to files, open a file, include an image as part of a link, define an anchor, and invoke a function.


<!-- Link to a server. -->
<A HREF="http://www.microsoft.com">Microsoft home page.</A>
<!-- Link to a file in the same directory. -->
<A HREF="home.htm">home.htm</A>
<!-- Open a file in the window specified by TARGET. -->
<A TARGET="viewer" HREF="sample.htm">Open in window</A>
<!-- Include an IMG element as a part of the link. -->
<A HREF="http://www.microsoft.com"><IMG SRC="images/bullet.png">link</A> 
<!-- Link to an anchor. -->
<A HREF="#anchor">anchor</A>
<!-- Define an anchor. -->
<A NAME="anchor">
<!-- Invoke a JScript function. -->
<A HREF="javascript:window.open()">link</A>

 

 

Build date: 3/8/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
<a name='target'></a> must close with a SEPARATE tag
In IE7, you could 'self-close' an anchor when used as a bookmark (e.g., <a name='target' />.  This was useful because the function of a bookmark is to scroll the browser window to a point (usually the beginning of a line).

IE8 appears to ignore the 'self-closed' aspect of an <a> tag, and instead scans forward to find the next </a>.  While the bookmark part still works, if (for instance) you have a <p> tag on the way, IE8 will 'self-close' that <p> tag prematurely.

So always use an explicit </a> tag with each bookmark <a name='target'> tag.
"a object" doesn't work when it contains a table

The note above says "A table object does not function properly when contained within an a tag." It is because a table is a block element and an anchor is an inline element. Inline element cannot contain block elements.