HTML code consists of HTML elements.
An element consists of an opening tag, followed by the element content, followed by a closing tag. An opening tag is of the form <elementName> and a closing tag is of the form </elementName>. The example code below shows a title element; the opening tag is <title>, the closing tag is </title> and the content is the text: Poles of Inaccessibility.
<title> Poles of Inaccessibility </title>
Some elements are empty, which means that they consist of only an opening tag (no content and no closing tag). The following code shows an hr element, which is an example of an empty element.
<hr>
An element may have one or more attributes, which are of the form attributeName="attributeValue". Attributes appear in the opening tag. The code below shows the opening tag for a table element, with an attribute called border. The value of the attribute in this example is "1".
<table border="1">
There is a fixed set of valid HTML elements (Table 3.1 provides a list of some common elements) and each element has its own set of possible attributes.
Certain HTML elements are compulsory. An HTML document must include a DOCTYPE declaration and a single html element. Within the html element there must be a single head element and a single body element. Within the head element there must be a title element. Figure 3.1 shows a minimal piece of HTML code.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>A Minimal HTML Document</title> </head> <body> Your content goes here! </body> </html>
|
Section 3.3 describes each of the common elements in a little more detail, including any important attributes, and which elements may be placed inside which other elements.
Element | Usage |
html | The container for all other HTML code. |
head | Information about the web page (not displayed). |
title | A title for the web page. |
link | Link to a CSS file. |
body | The main content of the web page. |
p | A paragraph (of text). |
img | An image. |
a | A hyperlink source or destination. |
h1 ... h6 | Section headings. |
table | A table (see tr and td). |
tr | One row within a table (see td). |
td | One column within a row of a table. |
hr | A horizontal line. |
br | A line break (forces a new line). |
ul | An unordered (bullet point) list (see li). |
ol | An ordered (numbered) list (see li). |
li | An item within a list. |
pre | Preformatted text. |
div | A generic block-level element (like a paragraph). |
span | A generic inline element (like a word). |
Comments in HTML code are anything within an opening
<!--
and a closing -->
. All characters, including
HTML tags, lose their
special meaning within an HTML comment.
Paul Murrell
This document is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 License.