August 2009

TITLE - Document Title

Syntax <TITLE>...</TITLE>
Attribute Specifications
Contents Plain text (including entities)
Contained in HEAD

The TITLE element gives the document's title. Each document must have exactly one TITLE within the HEAD. TITLE contains plain text and entities; it may not contain other markup.

A good TITLE should be short and specific to the document's content so that it can be used as a title for a user's bookmark, a title for the display window, and a link from a search engine. A suggested limit for the number of characters in a TITLE is 60.

STYLE - Embedded Style Sheet

Syntax <STYLE>...</STYLE>
Attribute Specifications
Contents An embedded style sheet
Contained in HEAD

The STYLE element embeds a style sheet in the document. Any number of STYLE elements may be contained in the HEAD of a document.

The required TYPE attribute of STYLE is used to specify the Internet media type of the style language. For Cascading Style Sheets, the TYPE attribute value should be text/css.

The optional TITLE attribute gives a title for the style sheet. Without a TITLE attribute, the style sheet is always applied when style sheets are enabled. With a TITLE attribute, the style sheet is automatically applied but the user may choose to disable the style sheet while keeping or enabling other style sheets. Style sheets with the same title are considered to be the same style sheet.

Many browsers ignore the TITLE attribute on style sheets and do not allow the user to selectively enable or disable individual style sheets.

The MEDIA attribute specifies the media on which the style sheet should be applied. This allows authors to restrict a style sheet to certain output devices, such as printers or aural browsers. The attribute's value is a comma-separated list of media descriptors. The following media descriptors are defined in HTML 4 and are case-sensitive:

  • screen, for non-paged computer screens;
  • tty, for fixed-pitch character grid displays (such as the display used by Lynx);
  • tv, for television-type devices with low resolution and limited scrollability;
  • projection, for projectors;
  • handheld, for handheld devices (characterized by a small display and limited bandwidth);
  • print, for output to a printer;
  • braille, for braille tactile feedback devices;
  • aural, for speech synthesizers;
  • all, for all devices.

Netscape 4.x incorrectly ignores any STYLE element with a MEDIA value other than screen. For example, MEDIA="screen, projection" will cause the style sheet to be ignored by Netscape 4.x, even if the presentation device is a computer screen. Netscape 4.x also ignores style sheets declared with MEDIA=all.

An example of an embedded style sheet follows:

<STYLE TYPE="text/css" MEDIA=screen>
<!--
BODY { background: url(foo.gif) red; color: black }
P EM { background: yellow; color: black }
.note { margin-left: 5em; margin-right: 5em }
-->
</STYLE>

Pre-HTML 3.2 browsers, unaware of the STYLE element, would normally show its contents as if they were part of the BODY, thus making the style sheet visible to the user. To prevent this, style languages like CSS allow the style sheet to be contained within an SGML comment (<!-- comment -->), as in the preceding example.

An embedded style sheet should be used when a single document has a unique style. If the same style sheet is used in multiple documents, then an external style sheet would be more appropriate.

SCRIPT - Client-side Script

Syntax <SCRIPT>...</SCRIPT>
Attribute Specifications
  • TYPE=ContentType (content-type of scripting language)
  • LANGUAGE=CDATA (scripting language name)
  • SRC=URI (external script location)
  • CHARSET=Charset (character encoding of external script)
  • DEFER (script execution may wait)
Contents An embedded script
Contained in HEAD, block-level elements, inline elements except SELECT and SCRIPT

The SCRIPT element includes a client-side script in the document. Client-side scripts allow greater interactivity in a document by responding to user events. For example, a script could be used to check the user's form input prior to submission to provide immediate notice of any errors by the user.

Note that not all browsers support client-side scripting, and supporting browsers allow the user to disable scripting. In particular, browsers on mobile phones often ship with scripting disabled for performance reasons. Authors should avoid dependence on client-side scripting wherever possible. The NOSCRIPT element can be used to provide content for browsers that do not support client-side scripting or have it disabled. In the case of form validation, any error checking done by the client-side script should be repeated by the server-side form processor.

Also note that different browsers support different variants of scripting languages with different bugs. Authors are encouraged to check their scripts on as many browsers as possible.

The required TYPE attribute of SCRIPT specifies the media type of the scripting language, e.g., text/javascript. However, many browsers only support the deprecated LANGUAGE attribute, which specifies the language name. Examples of supported LANGUAGE values include JavaScript, JavaScript1.1, and VBScript. The values are not case sensitive.

Browsers will ignore scripts with LANGUAGE values that they do not support. For example, Netscape 3.0 will execute scripts with LANGUAGE="JavaScript" or LANGUAGE="JavaScript1.1" but will ignore scripts with LANGUAGE="JavaScript1.2" or LANGUAGE="VBScript".

In the absence of the LANGUAGE attribute, browsers that do not support the TYPE attribute typically assume that the language is the highest version of JavaScript supported by the browser. Thus authors may safely omit the deprecated LANGUAGE attribute when using JavaScript.

An embedded script is given as the content of the SCRIPT element. The SRC attribute allows authors to reuse code by specifying an external script. The optional CHARSET attribute gives the character encoding of the external script, although this attribute is rarely needed in practice. When the SRC attribute is used, the embedded script is ignored. An example follows:

<SCRIPT TYPE="text/javascript" SRC="foo.js">
<!--
// embedded script ignored
// -->
</SCRIPT>

Netscape 4.x requires that external scripts be served with a Content-Type of application/x-javascript.

The DEFER attribute indicates that the browser may wait to parse the script until the rest of the document has been rendered. Scripts that use DEFER must not generate any document content, and should not be required to respond to user events (e.g., form submission) that may occur while the document is loading. The DEFER attribute can be useful for delaying scripts that pre-load images or harass the user with scrolling messages in the status bar.

The SCRIPT element may occur any number of times in the document HEAD or BODY. Typically the SCRIPT element is used in the HEAD unless it generates BODY content.

Pre-HTML 3.2 browsers, unaware of the SCRIPT element, will treat the content of SCRIPT as normal HTML. To make these browsers ignore the SCRIPT's content, scripting languages generally allow SGML comments to be used around an embedded script. For example:

<SCRIPT TYPE="text/javascript">
<!-- comment to end of line
document.write("foo");
// comment to end of line -->
</SCRIPT>

Note that "-->" is contained within a JavaScript single-line comment (started with two slashes).

Due to an unintuitive quirk of SGML, end tags are recognized within SCRIPT elements, but other kinds of markup--such as start tags and comments--are not. Almost all browsers ignore this rule, but authors should nonetheless avoid using strings such as "</P>" in their embedded scripts. JavaScript allows authors to use a backslash in the string to prevent it from being treated as an end tag, e.g., document.write("<\/P>").

META - Metadata

Syntax <META>
Attribute Specifications
Contents Empty
Contained in HEAD

The META element provides metadata such as a document's keywords, description, and author. Any number of META elements may be contained in the HEAD of a document.

META's NAME attribute provides a property name while the CONTENT attribute gives the corresponding value. The CONTENT attribute value may contain text and entities, but it may not contain HTML tags.

The optional SCHEME attribute gives the format of the property value. For example, a date property may require SCHEME="Month-Day-Year" to disambiguate the date from other formats such as SCHEME="Day-Month-Year".

There is no standard list of META properties, so authors may define whatever metadata they like. The following example defines the author of the document:

<META NAME=author CONTENT="Liam Quinn">

Some search engines use keywords and description properties, giving extra weight to a document's keywords and providing its description with the link to the document. Example:

<META NAME="description" CONTENT="A description of HTML 4.0's META element for metadata.">
<META NAME="keywords" CONTENT="META, meta element, metadata, metainformation, meta data, meta information, keywords, description, refresh, HyperText Markup Language, HTML, HTML4, HTML 4.0, Web Design Group, WDG, &lt;meta&gt; tag, &lt;META&gt; tag">

To avoid being truncated by search engines, the description should be brief--no more than 200 characters. Keywords are separated by commas and may be considered case sensitive by search engines. If the same keywords are repeated too often in the META element, some search engines will not index the document. Search engines typically only process the first 1000 characters of the keywords list.

Some search engines also support the robots property for indicating whether a document should be indexed and whether its links should be followed. The associated CONTENT value is a comma-separated list of case-insensitive directives:

  • index specifies that the page should be indexed while noindex specifies that it should not be indexed;
  • follow specifies that the page's links should be followed while nofollow specifies that they should not be followed;
  • all is equivalent to index,follow (the default value);
  • none is equivalent to noindex,nofollow.

For example, the following META element tells search engines and other robots not to index the page but to follow links on it:

<META NAME=robots CONTENT="noindex,follow">

The HTTP-EQUIV attribute may be used in place of the NAME attribute to indicate that the property should be treated as an HTTP header. Examples:

<META HTTP-EQUIV=Expires CONTENT="Thu, 29 Nov 2007 16:18:42 GMT">
sets the expiry date of the document. For proxy caches to honor the expiry date, a real HTTP header should be used instead of a META element. Consult a caching tutorial for details.
<META HTTP-EQUIV="Content-Script-Type" CONTENT="text/javascript">
sets the client-side scripting language for inline scripts to JavaScript.
<META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">
sets the style language for inline styles to CSS.
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=Shift_JIS">
sets the character encoding for the document to Shift_JIS (a Japanese encoding).
<META HTTP-EQUIV=Refresh CONTENT="10; URL=http://www.htmlhelp.com/">
tells the browser to load http://www.htmlhelp.com/ 10 seconds after the current document has finished loading. Not all browsers support this, so authors should provide an alternate means of moving to the new page where necessary. The Refresh header is sometimes used for "splash screens" or when a page has moved, but the technique is not very effective since users may not even be looking at the window that is to be refreshed. Some search engines penalize pages that use a Refresh of a few seconds or less.

LINK - Document Relationship

Syntax <LINK>
Attribute Specifications
Contents Empty
Contained in HEAD

The LINK element defines document relationships. Any number of LINK elements may be contained in the HEAD of a document. Many browsers lack support for LINK, so authors should not depend on the browser making the links available to the user.

The REL and REV attributes define the nature of the relationship between the documents and the linked resource. REL defines a link relationship from the current document to the linked resource while REV defines a relationship in the opposite direction. For example,

<LINK REL=Glossary HREF="foo.html">

indicates that foo.html is a glossary for the current document while

<LINK REV=Subsection HREF="bar.html">

indicates that the current document is a subsection of bar.html. The value of the REL and REV attributes is a space-separated list of link types.

Commonly used relationships include the next or previous document in a sequence, the starting page in a collection of documents, a document with copyright information, and information about the author. A document could define these relationships as follows:

<LINK REL=Prev HREF="base.html" TITLE="BASE - Document Base URI">
<LINK REL=Next HREF="meta.html" TITLE="META - Metadata">
<LINK REL=Start HREF="../" TITLE="HTML 4 Reference">
<LINK REL=Copyright HREF="/copyright.html" TITLE="Copyright Notice">
<LINK REV=Made HREF="mailto:liam@htmlhelp.com" TITLE="HTML 4 Reference Feedback">

While the value of REL and REV is case-insensitive, the Lynx browser renders the relationship exactly as given by the author. Authors should therefore be consistent in their case, and may wish to capitalize the first letter while using lowercase for the rest.

Authors can also use the LINK element to apply an external style sheet. REL=StyleSheet specifies a persistent or preferred style while REL="Alternate StyleSheet" defines an alternate style. A persistent style is one that is always applied when style sheets are enabled. The absence of the TITLE attribute indicates a persistent style.

A preferred style is one that is automatically applied. The combination of REL=StyleSheet and a TITLE attribute specifies a preferred style. Authors cannot specify more than one preferred style.

An alternate style is indicated by REL="Alternate StyleSheet". The user could choose to replace the preferred style sheet with an alternate one, though current browsers generally lack the ability to choose alternate styles.

A single style may also be given through multiple style sheets:

<LINK REL=StyleSheet HREF="basics.css" TITLE="Contemporary" TYPE="text/css">
<LINK REL=StyleSheet HREF="tables.css" TITLE="Contemporary" TYPE="text/css">
<LINK REL=StyleSheet HREF="forms.css" TITLE="Contemporary" TYPE="text/css">

In this example, three style sheets are combined into one "Contemporary" style that is applied as a preferred style sheet. To combine multiple style sheets into a single style, each style sheet's LINK must use the same TITLE.

LINK's MEDIA attribute specifies the media for which the linked resource is designed. With REL=StyleSheet, this allows authors to restrict a style sheet to certain output devices, such as printers or aural browsers. The attribute's value is a comma-separated list of media descriptors. The following media descriptors are defined in HTML 4 and are case-sensitive:

  • screen, for non-paged computer screens;
  • tty, for fixed-pitch character grid displays (such as the display used by Lynx);
  • tv, for television-type devices with low resolution and limited scrollability;
  • projection, for projectors;
  • handheld, for handheld devices (characterized by a small display and limited bandwidth);
  • print, for output to a printer;
  • braille, for braille tactile feedback devices;
  • aural, for speech synthesizers;
  • all, for all devices.

Netscape 4.x incorrectly ignores any style sheet linked with a MEDIA value other than screen. For example, MEDIA="screen, projection" will cause the style sheet to be ignored by Netscape 4.x, even if the presentation device is a computer screen. Netscape 4.x also ignores style sheets declared with MEDIA=all.

The optional HREFLANG and CHARSET attributes of LINK give the language and character encoding, respectively, of the link. The language should be specified according to RFC 1766; examples include en for English, en-US for American English, and ja for Japanese. Examples of character encodings include ISO-8859-1, Shift_JIS, and UTF-8.

The Alternate link relationship defines an alternate version of the document. Translations of a page can be identified by using REL=Alternate along with the HREFLANG attribute. Versions of the page tailored for specific media can be provided by combining REL=Alternate with the MEDIA attribute. Some examples follow:

<LINK REL=Alternate HREF="index.fr.html" HREFLANG=fr LANG=fr TITLE="Version française">
<LINK REL=Alternate HREF="index.ja.html" HREFLANG=ja CHARSET="Shift_JIS" TITLE="Japanese version">
<LINK REL=Alternate HREF="/distribution/html40.pdf" TYPE="application/pdf" MEDIA=print TITLE="PDF version">

Note that the LANG and DIR attributes apply to the text of the TITLE attribute, not to the content of the link.

The TARGET attribute is used with frames to specify the frame in which the link should be rendered. If no frame with such a name exists, the link is rendered in a new window unless overridden by the user. Special frame names begin with an underscore:

  • _blank renders the link in a new, unnamed window
  • _self renders the link in the current frame (useful for overriding a BASE TARGET)
  • _parent renders the link in the immediate FRAMESET parent
  • _top renders the link in the full, unframed window

In HTML 4, the TARGET attribute value is case-insensitive, so that _top and _TOP both have the same meaning. However, most browsers treat the TARGET attribute value as case-sensitive and do not recognize _TOP as having the special meaning of _top.

ISINDEX

Syntax <ISINDEX>
Attribute Specifications
Contents Empty
Contained in APPLET, BLOCKQUOTE, BODY, CENTER, DD, DEL, DIV, FIELDSET, FORM, HEAD, IFRAME, INS, LI, MAP, NOFRAMES, NOSCRIPT, OBJECT, TD, TH

The ISINDEX element defines a single-line text input. The label of the input field is specified using the element's PROMPT attribute. ISINDEX is deprecated in HTML 4 in favor of the INPUT element.

When the user presses the enter key within the input field, the input field's text is sent to the server in a query string appended to the document's base URI. The query string takes the form "?text+of+input+field"; spaces are encoded as "+".

BASE

Syntax <BASE>
Attribute Specifications
  • HREF=URI (base URI reference)
  • TARGET=FrameTarget (frame to render links in)
Contents Empty
Contained in HEAD

The BASE element defines the document's base URI for resolving relative URIs contained within the document. A document cannot contain more than one BASE element. When present, the BASE element must appear in the HEAD, prior to any elements that include a partial URI.

BASE's HREF attribute, required in HTML 4 Strict, specifies the absolute URI used to resolve relative URIs. See Using Relative URLs for more details on using and resolving relative URIs.

Most Web pages do not require an explicit base URI since the document's URI is a suitable base. An explicit base URI may be needed when the same document is available at different URIs or when the document has no URI (e.g., sending an HTML document by e-mail).

The TARGET attribute is used with frames to specify the frame in which all links in the document should be rendered by default. The target frame specified by BASE can be overridden by a given link using the link's TARGET attribute.

If no frame with the specified target name exists, the links are rendered in a new window unless overridden by the user. Special frame names begin with an underscore:

  • _blank renders the links in a new, unnamed window
  • _self renders the links in the current frame
  • _parent renders the links in the immediate FRAMESET parent
  • _top renders the links in the full, unframed window

In HTML 4, the TARGET attribute value is case-insensitive, so that _top and _TOP both have the same meaning. However, most browsers treat the TARGET attribute value as case-sensitive and do not recognize _TOP as having the special meaning of _top.

FRAMESET

Syntax <FRAMESET>...</FRAMESET>
Attribute Specifications
Contents One or more FRAMESET and FRAME elements, as well as an optional NOFRAMES
Contained in HTML

BODY

Syntax <BODY>...</BODY>
Attribute Specifications
  • BACKGROUND=URI (background image for document)
  • BGCOLOR=Color (background color for document)
  • TEXT=Color (text color for document)
  • LINK=Color (link color for document)
  • VLINK=Color (visited link color for document)
  • ALINK=Color (active link color for document)
  • ONLOAD=Script (document has been loaded)
  • ONUNLOAD=Script (document has been exited)
  • common attributes
Contents
Contained in

The BODY element contains the document body. BODY is required in non-frames documents, but its start and end tags are always optional. In frames documents, BODY must be contained within the NOFRAMES element, if NOFRAMES is used.

The BODY element contains the document's content. The content should be contained within block-level elements or SCRIPT elements, though HTML 4 Transitional also allows inline elements directly within BODY.

BODY takes a number of attributes for specifying the background and colors of the document on visual browsers. These attributes are deprecated in HTML 4 in favor of style sheets, which provide greater flexibility in suggesting the presentation of a document. BGCOLOR suggests a background color, TEXT suggests a text color, LINK suggests a link color, VLINK suggests a visited link color, and ALINK suggests an active link color (when the link is selected). If one of these attributes is given, then all of them should be included to ensure that the user's chosen colors do not interfere with those suggested in the <BODY> tag. Authors should not rely on the specified colors being used since browsers allow these colors to be overridden by the user.

The BACKGROUND attribute suggests a background image for tiling on the document canvas. To help ensure a readable document, the BGCOLOR, TEXT, LINK, VLINK, and ALINK attributes should always be included when BACKGROUND is given. The BGCOLOR will be used for those not loading images.

Style sheets allow more flexibility in suggesting a background image, including the ability to specify the position of the image, how the image is tiled, and whether the image should scroll with the document.

In addition to the core events common to most elements, BODY accepts the following event attributes for client-side scripting:

  • ONLOAD, when the document has been loaded;
  • ONUNLOAD, when the document is exited.

HEAD

Syntax <HEAD>...</HEAD>
Attribute Specifications
Contents Exactly one TITLE element, optional BASE and ISINDEX elements, and zero or more SCRIPT, STYLE, META, LINK, or OBJECT elements
Contained in HTML