A Beginner's Guide to HTML -- Part 1
In practical terms, HTML is a collection of platform-independent styles (indicated by markup tags) that define the various components of a World Wide Web document. HTML was invented by Tim Berners-Lee while at CERN, the European Laboratory for Particle Physics in Geneva.
This primer assumes that you:
If you haven't already selected your software, refer to an online listing of HTML editors (organized by platform) to help you in your search for appropriate software.
To denote the various elements in an HTML document, you use tags. HTML tags consist of a left angle bracket (<), a tag name, and a right angle bracket (>). Tags are usually paired (e.g., <H1> and </H1>) to start and end the tag instruction. The end tag looks just like the start tag except a slash (/) precedes the text within the brackets. HTML tags are listed below.
Some elements may include an attribute, which is additional information that is included inside the start tag. For example, you can specify the alignment of images (top, middle, or bottom) by including the appropriate attribute with the image source HTML code. Tags that have optional attributes are noted below.
NOTE: HTML is not case sensitive. <title> is equivalent to <TITLE> or <TiTlE>. There are a few exceptions noted in Escape Sequences below.
Not all tags are supported by all World Wide Web browsers. If a browser does not support a tag, it (usually) just ignores it.
Required elements are shown in this sample bare-bones document:
<html> <head> <TITLE>A Simple HTML Example</TITLE> </head> <body> <H1>HTML is Easy To Learn</H1> <P>Welcome to the world of HTML. This is the first paragraph. While short it is still a paragraph!</P> <P>And this is the second paragraph.</P> </body> </html>The required elements are the <html>, <head>, <title>, and <body> tags (and their corresponding end tags). Because you should include these tags in each file, you might want to create a template file with them. (Some browsers will format your HTML file correctly even if these tags are not included. But some browsers won't! So make sure to include them.)
Click to see the formatted version of the example. A longer example is also available but you should read through the rest of the guide before you take a look. This longer-example file contains tags explained in the next section.
This is an excellent way to see how HTML is used and to learn tips and constructs. Of course, the HTML might not be technically correct. Once you become familiar with HTML and check the many online and hard-copy references on the subject, you will learn to distinguish between "good" and "bad" HTML.
Remember that you can save a source file with the HTML codes and use it as a template for one of your Web pages or modify the format to suit your purposes.
For example, you might include a shortened title of a book along with the chapter contents: NCSA Mosaic Guide (Windows): Installation. This tells the software name, the platform, and the chapter contents, which is more useful than simply calling the document Installation. Generally you should keep your titles to 64 characters or fewer.
HTML has six levels of headings, numbered 1 through 6, with 1 being the most prominent. Headings are displayed in larger and/or bolder fonts than normal body text. The first heading in each document should be tagged <H1>.
The syntax of the heading element is:
Do not skip levels of headings in your document. For example, don't start with a level-one heading (<H1>) and then next use a level-three (<H3>) heading.
Unlike documents in most word processors, carriage returns in HTML files aren't significant. So you don't have to worry about how long your lines of text are (better to have them fewer than 72 characters long though). Word wrapping can occur at any point in your source file, and multiple spaces are collapsed into a single space by your browser.
In the bare-bones example shown in the Minimal HTML Document section, the first paragraph is coded as
<P>Welcome to the world of HTML. This is the first paragraph. While short it is still a paragraph!</P>
In the source file there is a line break between the sentences. A Web browser ignores this line break and starts a new paragraph only when it encounters another <P> tag.
Important: You must indicate paragraphs with <P> elements. A browser ignores any indentations or blank lines in the source text. Without <P> elements, the document becomes one large paragraph. (One exception is text tagged as "preformatted," which is explained below.) For example, the following would produce identical output as the first bare-bones HTML example:
<H1>Level-one heading</H1> <P>Welcome to the world of HTML. This is the first paragraph. While short it is still a paragraph! </P> <P>And this is the second paragraph.</P>To preserve readability in HTML files, put headings on separate lines, use a blank line or two where it helps identify the start of a new section, and separate paragraphs with blank lines (in addition to the <P> tags). These extra spaces will help you when you edit your files (but your browser will ignore the extra spaces because it has its own set of rules on spacing that do not depend on the spaces you put in your source file).
NOTE: The </P> closing tag can be omitted. This is because browsers understand that when they encounter a <P> tag, it implies that there is an end to the previous paragraph.
Using the <P> and </P> as a paragraph container means that you can center a paragraph by including the ALIGN=alignment attribute in your source file.
<P ALIGN=CENTER> This is a centered paragraph. [See the formatted version below.] </P>
This is a centered paragraph.
To make an unnumbered, bulleted list,
Below is a sample three-item list:
<UL> <LI> apples <LI> bananas <LI> grapefruit </UL>
The output is:
The <LI> items can contain multiple paragraphs. Indicate the paragraphs with the <P> paragraph tags.
A numbered list (also called an ordered list, from which the tag name derives) is identical to an unnumbered list, except it uses <OL> instead of <UL>. The items are tagged using the same <LI> tag. The following HTML code:
<OL> <LI> oranges <LI> peaches <LI> grapes </OL>
produces this formatted output:
A definition list (coded as <DL>) usually consists of alternating a definition term (coded as <DT>) and a definition definition (coded as <DD>). Web browsers generally format the definition on a new line.
The following is an example of a definition list:
<DL> <DT> NCSA <DD> NCSA, the National Center for Supercomputing Applications, is located on the campus of the University of Illinois at Urbana-Champaign. <DT> Cornell Theory Center <DD> CTC is located on the campus of Cornell University in Ithaca, New York. </DL>
The output looks like:
The <DT> and <DD> entries can contain multiple paragraphs (indicated by <P> paragraph tags), lists, or other definition information.
The COMPACT attribute can be used routinely in case your definition terms are very short. If, for example, you are showing some computer options, the options may fit on the same line as the start of the definition.
<DL COMPACT> <DT> -i <DD>invokes NCSA Mosaic for Microsoft Windows using the initialization file defined in the path <DT> -k <DD>invokes NCSA Mosaic for Microsoft Windows in kiosk mode </DL>The output looks like:
Lists can be nested. You can also have a number of paragraphs, each containing a nested list, in a single list item.
Here is a sample nested list:
<UL> <LI> A few New England states: <UL> <LI> Vermont <LI> New Hampshire <LI> Maine </UL> <LI> Two Midwestern states: <UL> <LI> Michigan <LI> Indiana </UL> </UL>
The nested list is displayed as
Use the <PRE> tag (which stands for "preformatted") to generate text in a fixed-width font. This tag also makes spaces, new lines, and tabs significant (multiple spaces are displayed as multiple spaces, and lines break in the same locations as in the source HTML file). This is useful for program listings, among other things. For example, the following lines:
<PRE> #!/bin/csh cd $SCR cfs get mysrc.f:mycfsdir/mysrc.f cfs get myinfile:mycfsdir/myinfile fc -02 -o mya.out mysrc.f mya.out cfs save myoutfile:mycfsdir/myoutfile rm * </PRE>
#!/bin/csh cd $SCR cfs get mysrc.f:mycfsdir/mysrc.f cfs get myinfile:mycfsdir/myinfile fc -02 -o mya.out mysrc.f mya.out cfs save myoutfile:mycfsdir/myoutfile rm *
The <PRE> tag can be used with an optional WIDTH attribute that specifies the maximum number of characters for a line. WIDTH also signals your browser to choose an appropriate font and indentation for the text.
Hyperlinks can be used within <PRE> sections. You should avoid using other HTML tags within <PRE> sections, however.
Note that because <, >, and & have special meanings in HTML, you must use their escape sequences (<, >, and &, respectively) to enter these characters. See the section Escape Sequences for more information.
Use the <BLOCKQUOTE> tag to include lengthy quotations in a separate block on the screen. Most browsers generally change the margins for the quotation to separate it from surrounding text.
In the example:
<BLOCKQUOTE> <P>Omit needless words.</P> <P>Vigorous writing is concise. A sentence should contain no unnecessary words, a paragraph no unnecessary sentences, for the same reason that a drawing should have no unnecessary lines and a machine no unnecessary parts.</P> --William Strunk, Jr., 1918 </BLOCKQUOTE>
the result is:
The <ADDRESS> tag is generally used to specify the author of a document, a way to contact the author (e.g., an email address), and a revision date. It is usually the last item in a file.
For example, the last line of the online version of this guide is:
<ADDRESS> A Beginner's Guide to HTML / NCSA / firstname.lastname@example.org / revised April 96 </ADDRESS>
The result is:A Beginner's Guide to HTML / NCSA / email@example.com / revised April 96
NOTE: <ADDRESS> is not used for postal addresses. See "Forced Line Breaks" below to see how to format postal addresses.
The <BR> tag forces a line break with no extra (white) space between lines. Using <P> elements for short lines of text such as postal addresses results in unwanted additional white space. For example, with <BR>:
National Center for Supercomputing Applications<BR> 605 East Springfield Avenue<BR> Champaign, Illinois 61820-5518<BR>The output is:
National Center for Supercomputing Applications
The <HR> tag produces a horizontal line the width of the browser window. A horizontal rule is useful to separate sections of your document. For example, many people add a rule at the end of their text and before the <address> information.
You can vary a rule's size (thickness) and width (the percentage of the window covered by the rule). Experiment with the settings until you are satisfied with the presentation. For example:
<HR SIZE=4 WIDTH="50%">displays as:
A Beginner's Guide to HTML / NCSA / firstname.lastname@example.org / revised April 96 edits: 7/96; 9/96; 1/97