target Attribute


 

Where to use the target Attribute


Description

The target attribute specifies the window or frame in which the author would like the href URI of a link or the action URI of a form to be loaded. If specified on the base element, this attribute sets the desired default behaviour for all links or forms in the document. This default behaviour may of course be overridden by target attributes on the individual links or forms themselves.

Until recently, the target attribute was not passing W3C Validation but, now that it is (as at 15th April 2009, anyway) I have included the documentation on this site.

The target attribute may be assigned one of the following reserved words:

"_blank"
URI should be loaded in a new, unnamed window (or tab, depending on the browser and/or user settings).
"_self"
URI should be loaded in the same window (and the same frame, if appropriate) as the link (or form), replacing the current document. This is the default action if the target attribute is omitted both from the link and from the document's base element, if it exists.
"_parent"
URI should be loaded in the immediate frameset parent of the document. This is not likely to be useful when writing solely in XHTML 1.1 since the Frames Module is not included by default (and is thus not documented on this site).
"_top"
URI should be loaded in the full body of the window, not in any frame. The behaviour of this value is the same as the behaviour of _self if the document is already at the top level. _top is useful in order to break out of multiply nested frames which, again, will probably not be common if writing purely XHTML 1.1.

Otherwise, the value of the target attribute is treated as a target name and if a frame with that target name exists then the URI is loaded in that frame, replacing the existing document. Otherwise, the URI is loaded in a new window which is assigned that target name; if the user subsequently follows another link with that same target name, the target URI will also be loaded in this window, replacing the existing document.

The HTML 4.01 specifications say that all target names should begin with a letter, i.e. [a-zA-Z], and that all other names should be ignored by user agents (ref: *HTML 4.01 - Frame target names). In practice, this isn't always the case. Also, Internet Explorer has defined two additional values "_search" and "_media" which are specific to IE and indicate that the link should be opened in the search pane or the media bar respectively.

For example, the following link should be opened within a new browser window (or tab, depending on the browser and on the user's settings):

<a href="http://www.webcompliant.co.uk/" target="_blank">Webcompliant Home Page</a>

This is rendered as:

Note: Having said all this, it is probably best in most circumstances to avoid the target attribute and let the user decide on where to open a particular link. However, as long as it's used with a bit of common sense, I don't see the need to ban its use entirely.
Also, bear in mind that the use of target="_blank" in particular can often be overridden in user preferences, for example in Firefox by setting the preference browser.link.open_newwindow to 1 - see *trilithium.com - The folly of target="_blank" for a discussion.

Ref: *HTML 4.01 - Specifying target frame information.


Page Footer & Copyright

Copyright © Sally Maughan 2005-2009 (Page last updated on 16 May 2009)

*Valid XHTML 1.1 - hosted by *Openstrike

Content based on the W3C Working Draft: *XHTML 1.1 and Recommendation: *XHTML Modularisation 1.1.

W3C, XHTML, XML, HTML, CSS and MathML are *Trademarks of the W3C (*MIT, *ERCIM, *Keio) with which the site's author has no connection.


Up, Next & Previous Links

Your Location

Home > XHTML 1.1 Home > XHTML 1.1 Indexes > Attribute Index (XHTML 1.1) > target Attribute (XHTML 1.1)