Contents

Further reading

Quick Introduction to HTML

What is HTML?

Why learn HTML?

Many web page authors build their web sites using commercial software packages, called web site builders. These packages shield the author from the HTML code they produce. This is a good thing, by and large, allowing authors to produce very elaborate and beautiful pages conveniently. So why bother with HTML?

Web page builders ultimately produce HTML. To make full use of a web page builder, and to understand its limitations, you should understand the HTML that it produces.

Often, you may want to alter a site, but don’t have access to the software with which it was produced. In this case, some knowledge of HTML is indespensible.

HTML files

An HTML file...

Tags and attributes

All commands in HTML are tags, which consist of a special keyword between angle brackets. For instance, the tag
<em>
indicates to emphasize the following text.

Most HTML tags require an end tag which looks just like the tag except the keyword starts with a slash, like this one:
</em>
which indicates to stop emphasizing the text.

So the HTML code
This is <em>emphasized</em> text.
is rendered in a web browser as

This is emphasized text.

A few tags, notably line break <br>, horizontal rule <hr> and <img> for images, are self-terminating, meaning they don’t take an end tag. The preferred way to code them is to end the tag with a slash, like so:
<br />, <hr />, <img.../> .

Any tag can also contain attributes, which provide further description for the element.

For example, the tag img which loads an image file into the document, requires a path to the image file, specified by the src attribute, and can take an alt attribute that gives an alternative textual version of the image. Such a tag might look like this:

<img src="/path-to-imagefile" alt="my image description" />

The attribute consists of attribute name, followed by an equals sign, then by the value, which is a character string in quotes.

Comments

There is a provision in HTML for code comments, which is text you can put in the code but does not show up in the web page.

You can use comments to make a memo to yourself about why you coded something in some particular way, or to “comment out” a chunk of HTML code that you want to disable temporarily.

Any text between the “begin comment” marker
<!--
and the “end comment” marker
-->
is completely ignored by web browsers.

For instance, if your HTML document contains the code
<!-- This is just a comment. -->
the browser will not display the code.

Document structure

All HTML documents should contain at least the html start and end tags, to indicate where the HTML begins and ends. These html tags should enclose a single head block, followed by a single body block:

<html>
<head>
The title and other coding information goes in this head block
</head>
<body>
The part of your document that will show in the browser goes in this body block
</body>
</html>

Most of the content of the web page goes in the body block. Some information about the web page goes in the head block.

The title

The only head block tag we will discuss here is <title>. Typically, a web browser will display the title of the document in the top of the browser window. Also, in browsers that have a “bookmarks” or “favorites” list, the title is the name given to the document in the list.

For example, if you put the code
<title>My Web Page</title>
in the head block of your HTML document, the browser should put the text “My Web Page” at the top of the window when you look at your web page.

Text

The information content of a typical HTML document is its text. Any text in your document should be enclosed in some kind of tag.

In most tags, white space such as consecutive space characters, tab characters, and line endings, are replaced by a single space. Line-breaking within a tag is handled automatically by the browser. (The <pre> tag is the one exception; see below.) To specify how the page text appears in the web browser, you must use HTML tags or styles.

To make a vertical break between sections of text, such as paragraphs or section headers, put the sections between separate pairs of block tags. There are several types of block tags.

To specify the formatting of the text (the font size, shape, etc) within a single line, use inline markup tags.

Lists

HTML is especially well suited for outline-style documentation, such as this document. It provides several flexible types of lists, which may be nested.

Tables

Tables are one of the most powerful things in HTML. Beyond allowing for neatly organized table data, they are the only means in pure HTML to arrange text into columns.

The data in the table is placed between <table> start and end tags. Each row of the table is indicated by a table row <tr> tag. Each item in a row is indicated by either a table data <td> or a table heading <th> tag.

The border of the table is controlled by the border attribute. The default value of "0" indicates no border. Other values are typically interpreted as the width of the border line.

Both the <table> and <td> tags take a width attribute, which can be a percentage, such as width="100%", or a number of pixels. A percentage here refers to the width of the entity that contains the table.

For example this code

<table border="1">
<tr><th>header one</th><th>header two</th></tr>
<tr><td>data one</td><td>data two</td></tr>
<tr><td>data three</td><td>data four</td></tr>
</table>

is rendered as

header oneheader two
data onedata two
data threedata four

The spacing between table cell contents and its border can be specified with the cellpadding attribute of the <table> tag, and the space between cells in the table can be specified with the cellspacing attribute. The value of both these tags is a number, which is rendered as a number of pixels.

By default, the contents of a cell are centered vertically on the cell. The valign attribute of the <td> tag can force the contents to be aligned to the top or bottom of the cell with the top and bottom values, respectively, or force the first line of text of the cell to align with that of the other cells with the baseline attribute.

<table border="1">
<tr><td width="10">several lines of text</td>
<td width="10" valign="baseline">fewer lines</td></tr>
</table>

is rendered as

several lines of textfewer lines

Without the valign="baseline" attribute, it is rendered as

several lines of textfewer lines

A single cell in a table can be made to cross multiple rows and columns by specifying its rowspan and colspan attributes.

For more thorough information on HTML tables, see Quick HTML—Tables.

Horizontal Rule

The horizontal rule tag makes a horizontal line across the page. It is self-terminating, so is coded as <hr />.

There are tricks with <table> and horizontal rule that can make shorter horizontal lines. For example, the code

<table width="70%" border="0" cellspacing="0" cellpadding="0">
<tr><td width="10%"></td><td width="80%"><hr /></td></tr>
</table>

is rendered as


URL’s—Uniform Resource Locators

Web pages are best when they contain references to other documents on the Internet, such as pictures and other web pages. A picture in a web page is a separate file from the HTML file, and when you click on a link in a web page, that might take you to another HTML file altogether.

All outside documents are referred to within a HTML document in the same way, using a URL, or Uniform Resource Locator. A URL indicates the means by which to get a file, which Internet site the file is on, and a path to that file.

A typical URL looks like this:
protocol://server-address/dir1/dir2/file-name
The protocol is the network communications protocol to use to get the file. It is often http, which stands for “hypertext transfer protocol”, which is the main protocol of the World Wide Web. The server-address is the Internet address of the server the file is on, for instance “www.w3.org”. The rest of the URL is the directory path and filename of the file.

The protocol and server-address can be left off to indicate that the file is on the same server as the current web page. If the URL begins with a slash, the directory path is assumed to be relative to the default directory of the server:
/dir1/dir2/file-name
If the URL doesn’t begin with a slash, the directory path is assumed to be relative to the current HTML document
dir2/file-name

Images

An image can be included in a web page by means of the image tag <img>. The image itself is contained in a separate file, usually either a GIF or a JPEG file. Generally, code like
<img src="URL-to-imagefile" alt="my image description" />
where URL-to-imagefile describes the location of the image file to be displayed.

The size of the image isn’t known until the image is successfully loaded. You can leave space in the page for the image by specifying the width and height attributes of the image tag.

If your image contains any information that might be lost if the image doesn’t load, you can specify this in the text of the alt attribute. This text is also displayed by text-only web browsers, such as lynx.

Links

A web page can contain links to other web pages, and also links to other parts of the same page. These links put the hyper into hypertext.

To make a link to another web page, use the anchor tag <a> with the href attribute specifying the URL of the other page.

For example, the code
<a href="http://www.w3.org/"> The W3 Organization</a>
is rendered as

The W3 Organization

If you click on it with your mouse, the browser will take you to the web page specified by the href attribute value, "http://www.w3.org/".

For more information on URL’s, see “What is a URL?” We will show a few simple cases here.

The path can be a complete URL, like
http://server-name/dir1/dir2/other.html
or a path relative to the current HTML document
dir2/other.html
or a path relative to the root directory of the server of the current page
/dir1/dir2/other.html

To make a link to another part of the current page, use the anchor tag with the id attribute to label a place to go in the document. For instance, I put the code
<a id="WHAT"></a>
at the beginning of this document. The following code
<a href="#WHAT">Back to --&gt;What is HTML</a>
is rendered as

Back to --> What is HTML

Click on it to see what it does.