Element
From dictionary.com:
"An element is a document structuring unit declared in the DTD. The element's content model is defined in the DTD, and additional semantics may be defined in the prose description of the element." Source: XHTML™ 1.0 The Extensible HyperText Markup Language (Second Edition); W3C Recommendation 26 January 2000, revised 1 August 2002: Section 2.2. General Terms
Elements are the basic components of the HTML document. Some examples are the document's HEAD and BODY.
Elements are not the same thing as TAGS, which are the symbols used to define the elements in source code. (Think of the difference between numbers and numerals. There is only one number two, which is represented using numerals such as 2 or II.)
Tags in HTML are distinguished by paired angle brackets <>.
Most elements are written with a pair of starting and ending tags, for example <head></head> or <body></body>.
Attribute
From dictionary.com:
"An attribute is a parameter to an element declared in the DTD. An attribute's type and value range, including a possible default value, are defined in the DTD." Source: XHTML™ 1.0 The Extensible HyperText Markup Language (Second Edition); W3C Recommendation 26 January 2000, revised 1 August 2002: Section 2.2. General Terms
Attributes specify the characteristics of elements. They are written in the tag, after the element symbol, for example <body id="page1">.
An HTML 4 document is composed of three parts:
Whitespace (spaces, newlines, tabs, and comments) may appear before or after each section. Sections HEAD and BODY should be contained within the HTML element.
Here's an example of a basic HTML 4 document:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<HTML>
<HEAD>
<TITLE>My first HTML document</TITLE>
</HEAD>
<BODY>
<P>Hello world!
</BODY>
</HTML>
Many writers omit the DOCTYPE declaration. The browser has to guess what version to use. If it guesses wrong, the document may not be rendered the way the author intended.
Notice that in HTML 4.01, the ending tag for a paragraph (</P>)is optional.
The beginning of an XHTML document is a little more complicated.
To be a valid XHTML document, it must have a DOCTYPE declaration. There are three possibilities in XHTML 1.0.
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
The most rigorous form of the 1.0 standard. Required clean structural mark-up, free of any markup associated with layout. W3C's Cascading Style Sheet language (CSS) will handle font, color, and layout effects.
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
A modified version that allows some use of HTML 4.01 for compatibility with older browsers.
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
A modified version for documents that use frames to divide the window.
XHTML 1.1 is the most recent version. The declaration for XHTML 1.1 is:
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.1 Frameset//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml11.dtd">
An XML declaration is required when the character encoding of the document is other than the default UTF-8 or UTF-16. (More on these in a later class.) A typical XML declaration looks like:
<?xml version="1.0" encoding="UTF-8"?>
Here is a complete short XHTML document.
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml11.dtd">
<html>
<head>
<title>XHTML Example</title>
</head>
<body>
<p>The body is almost the same.</p>
<ul>
<li>A list item!</li>
<li>A list item!</li>
<li>A list item!</li>
</ul>
</body>
</html>
The tags are all in lowercase, and the paragraph has an end tag.
Internet Explorer 6 has a flaw. It will not recognize the DOCTYPE if the XML declaration (or anything else) comes before the DOCTYPE declaration. But if you skip the XML declaration tag, the validator will complain that there is no language encoding specified.
The fix is to specify the language in a META element. The tag should be in the HEAD.
<meta http-equiv="content-type" content="text/html; charset=character-set" />
Here is a short XHTML document using that tag .
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml11.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=character-set" />
<title>XHTML Example</title>
</head>
<body>
<p>The body is almost the same.</p>
<ul>
<li>A list item!</li>
<li>A list item!</li>
<li>A list item!</li>
</ul>
</body>
</html>
Checking a document against a specific standard is called validation. In the case of formally defined languages such as HTML and XHTML it can be carried out automatically. The W3C has a markup validator at http://validator.w3.org/. You just enter the URL of your published document. If you have a local file that is not yet published, you can upload the file for validation.
The Web Developer Toolbar extension for Firefox has tools for validating the page that is currently being displayed in the browser. The report opens in a new tab. Note: If you have a home firewall, you may need to turn off the "privacy protection" to use this tool.
<!-- ... -->: commentThe above list mentions about one-third of the elements in HTML 4.01. Here is a list of all 91 HTML 4.01 elements. If a tag is not in this list, then it isn't an official element.
The elements in an XHTML document must be in the proper relationship to each other. If they are correctly nested, you can draw diagram which shows the inner elements as branches from the outer ones.
In class, work with this document with validation errors.
Hood College Department of Computer Science: Course materials © 1997-2006 by Elizabeth Chang.