HTML Root, HEAD and BODY Tags | |
---|---|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
The html element is the "root" element
of the document, and
the opening and closing html tags enclose all the data
in the html document proper.
The root element of the document must
contain a declaration specifying the "XML namespace" (xmlns).
Including the "XML language"
declaration (xml:lang) is "strongly suggested." So is using
the deprecated "lang" attribute, for "backward compatibility"
with old browsers.
lang="en"><head> <title> </title> </head> <body> </body> </html> |
|
<head> <title> </title> </head> |
The head tags contain instructions
for web browsers and "behind-the-scenes"
internet applications, e.g.,
search-engine robots; head data is
not displayed on the web page itself. Only
the document title must
be contained inside the head
element, but other elements
usually appear, including tags
that define meta, link,
style, and script
elements. EXAMPLE:
<head> <title>Ed's Guide to XHTML</title> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <link rel="stylesheet" type="text/css" href="class.css" /> <script type="text/javascript" src="class.js"> </script> </head> |
<title> </title> | The title is the one required element that falls inside the head element. This title shows up in the browser's title bar, and is used by the browser if the page is bookmarked. |
<meta /> |
The
meta element is used primarily
to provide instructions to the browser or
to describe the content of the web page for
indexing. It appears only within the
head of the html file, but may be
repeated as many times as needed. Each
meta tag will have at least two
attributes: one to identify the function of
the tag, and the other to provide the
"content." Choose the first attribute(s) from among:
content="?"
EXAMPLES:
<meta
http-equiv="Content-Type"
NOTE: The first example defines the "character set"
(basically, the alphabet and punctuation marks) that the
browser should use, so this particular meta element
should always be included.
content="text/html; charset=ISO-8859-1" /> <meta name="keywords" content="html,xhtml,markup language" /> <meta scheme="day-month-year" name="revised" content="09-12-2001" /> |
The self-closing link tag creates
a connection with another document,
especially with an external "style sheet"
that specifies how defined elements should
be displayed. It appears only in the
head, but may be repeated as many
times as needed. Among the possible
attributes, those for
"relationship," "type,"
and
"hypertext reference"
(which specifies the
URL
of the linked document) are the most used.
EXAMPLE:
<link rel="stylesheet"
type="text/css" href="name.css" /> |
<style type="text/css"> selector1 { property: value } selector2 { property: value ; property: value } </style>
The style element is the place to create an
"internal" style sheet, an important part of a prescribed system called
Cascading Style Sheets (CSS).
Unfortunately, there are compatibility problems with coding for this element among past, present, and future browsers, so the best solution is: DON'T USE THIS TAG! At least for the time being. Instead, use the link tag to an "external" style sheet, and apply "inline" stylistic features (using the style, class, and id attributes) directly to tags within the body of the document. |
|
<script type="?"> </script> | The script element is used in both the head and
body of the document to insert programming code, such as
JavaScript. It may be repeated as often as you need it.
Putting scripts in XHTML that were originally formulated for the old HTML encoding is problematic. The problem is that script languages typically make use of characters that signify tags in XML, namely: the less-than symbol (<), the ampersand (&), and the character string: ]]>
The "tag" function
can be overridden by encapsulating the script in a "CDATA" (i.e., character data) element:
<![CDATA[ the script goes here ]]>
But, the CDATA tag confuses many
current browsers, so the best solution is to put your JavaScripts in a separate
document (created in Notepad and saved with the filename exension: .js),
and then refer to it with a "system
resource controller" attribute (src).
EXAMPLE:
<script
type="text/javascript"
[NOTE: The language="javascript" attribute has been deprecated and so should be omitted,
even though you will still see it all over the web to specify which version of JavaScript has been used.
Also, even though the script
tags are "empty" as used here, you should use
the opening and closing tag pair rather than
turning it into a self-closing tag.]
src="my_scripts.js"> </script> |
<body></body> | Opening and closing body tags enclose all the content that actually appears as the web page in the browser window. The body may include graphical and audio-visual elements in addition to text. |