The tags discussed in this section convey to the browser header information about the document. Examples are: the title, the content, the description, keywords, style sheets, and scripts. Not all browsers utilize the supplied information. A part of this, so-called meta information, is utilized by search engines. This page briefly mentions use of the most common header elements: title, meta, link, script, noscript and style.
All tags discussed in this section are contained in the head element. Only one such element, followed by the body or frameset elements, is admissible in the document. Content of the head element is not visible in the browser's viewing area, perhaps except the content of the noscript element in case when script execution is disabled for security reasons or due to the construction of an older browser.
The title tag belongs to an element displaying the tile in the browser's title bar. It is the most frequently used element, which looks like this:
<title> My Web Page </title>
The meta tag determines a self-closing element with these attributes: name, http-equiv, and content. Only the name or the http-equiv attribute, which must be followed by the content, can be used. The http-equiv attribute should force the server send the content via a header and some browsers will treat the content as sent in a header. Here are some examples:
<meta http-equiv="Content-Type" content="text/html;
charset=utf-8" />
<meta http-equiv="Content-Language"
content="CZ" />
<meta name="Revisit-After" content="30 days" />
The link is a somewhat futuristic html tag currently used only for import of favicons and CSS style sheets. The associated element has no content and consequently, it is self-closing. Its attributes are: rel, type, href, rev and title. Favicon is the abbreviation for favorite icon, which must be placed in the root directory should the link function properly. Typical examples are
<link rel="stylesheet" type="text/css" href="index.css" />
<link rel="shortcut icon" type="image/icon"
href="/favicon.ico" />
<link rev="made" href="mailto:mymail@company.com" />
Link is also intended for web site navigation, a feature not supported by most browsers. In presence of such links, the browser should create in the button-bar buttons for browsing of the web site. In that case, rel indicates relation of the url in the href attribute to the current document. Some of the recognized navigation rel values are: previous, next, up, home, index, glossary, help, copyright and toc.
The script element contains, surprisingly, script. Though JavaScript is the most common, it can be Visual Basic (VBScript), Tcl, or variants of JavaScript, its predecessor, the Live Script, or its standardized version, ECMA Script. In sake of simplicity and clarity it is better to import scripts from external files, using the src attribute, and leave the content of the script element empty. If no attributes are specified, browsers assume that the script element contains JavaScript. The most important attributes are type, charset and src. The type specifies the script language: text/ecmascript, text/javascript, application/ecmascript, application/javascript, text/vbscript, text/tcl. Charset informs the browser about the character encoding used in the script. src specifies the URL of the script file to be imported. Examples of use follow.
<script type="text/javascript">
document.write("Hello World!");
</script>
<script type="text/javascript" src="hello.js">
</script>
If a browser cannot execute a script because the script execution is disabled or it is unaware of the script tag, then an alternate content can be specified in the noscript tag. To prevent display of the script in the viewer, it is advised to enclose it in the SGML comment:
<script type="text/tcl">
<!--
...some Tcl script to insert data...
-->
</script>
<noscript>
<p>
If you see this text, access the
<a href="http://someplace.com/data">data</a>
here.
</p>
</noscript>
The style tag defines a style element, the content of which are short CSS codes. It is useful during the design period. A preferred practice is keeping style sheets in separate files imported using the link command above. A simple example follows.
<style type="text/css">
body{
text-align:center;
color:orange;
background-color:lightgrey;
}
</style>
Base defines a self-closing element telling the browser how to complete the URL provided as href and src attributes. The base must be placed in the header element. For example
<base href="http://eminf.com/" />
<link rel="stylesheet" type="text/css" href="index.css" />
is equivalent to
<link rel="stylesheet" type="text/css"
href="http://eminf.com/index.css" />
Web Design Group HTML Help and Web Authoring Reference, Web Design Group , 2006
Markup Validation Service, World Wide Web Consortium , 2006