|
Very basic primer for HTML languageLast revision July 20, 2004 HTML is a "mark-up language", similar in principle to the computer typesetting language TeX, but vastly simplified. You embed commands, called "tags", within the document text to define the logical parts of the document, such as paragraphs, lists, headings, links to other pages, etc. The Web browser then interprets these tags to format the page for viewing. Browsers may differ in how they format, for example, by using different styles or sizes of fonts, or different amounts of white space or indentation around sections. Many browsers let the user select these formatting characteristics. The key thing to remember is that the browser will be formatting the document for the viewer. It will ignore any text formatting that you do directly, such as indenting lines or breaking text into lines of certain lengths, unless it is done with an HTML tag.
HTML tags all follow this same format:
Because the left and right arrow bracket characters (< and >) are used to
delimit tags, they cannot be used in ordinary text. Instead, if you want to
show one of these bracket characters in your text, you must use the special
symbolic names:
There are many special characters, such as foreign language accented letters,
that may be used in your document with the "&" prefix. You will need to check
an HTML reference to see the list. The ampersand (&) character itself cannot
be used directly in your text because it is used for referencing special characters.
To use an actual ampersand in your text, use the symbolic name
HTML tags may be freely interspersed with the text. Either of these input documents would create the same output in the browser:
This is a sentence with
Tag names and attributes may be in either upper or lower case (or a mixture). For example, you can use all uppercase letters for tag names to make them stand out when editing the file. But proposed future extensions to HTML may require that tags be all lower case.
Most HTML tags are used in pairs, one to begin and another to end the text to
which they are meant to apply. Attributes may only go into the beginning tag.
The ending tag has the same tag name as the beginning, but prefixed with the
slash (/) character. For example, the tag to define an unordered list (items
shown with bullet characters) is
"<ul>".
At the beginning of the list, you would have the beginning tag
At the end of the list, you would have the corresponding ending tag
If you are missing an ending tag, your Web browser is not going to complain. It is just going to mis-format your document.
Other HTML tags are used singly, because they simply mark a location in the
text where some operation is to occur, rather than needing to span or delimit a
section of text. The two most common ones are:
Certain HTML tags are required in all documents. If you have only simple text,
and you want the browser to make all decisions about how to format, you only
need these:
In practice, that minimum set of tags doesn't get you very far. It doesn't
even allow you to specify paragraphs - all your text would appear as a single
long paragraph. So in practice, these additional formatting tags are sure to
be used within your document. Type-style tags (such as
<em>)
can be nested within each other, with cumulative effects.
The
"<img>"
tag is used to include a graphic image file. It is
used by itself, not in a pair. It can appear anywhere in the BODY section of a
document, interspersed with the text. Browsers will
automatically download and display such images wherever this tag is
encountered in the document.
The image inclusion tag has the syntax:
The URL (Uniform Resource Locator syntax) refers to the location of the image file. The ALT attribute is optional. It can be used to specify some text that will be presented instead of the image, if the browser is incapable of handling graphics images (such as the lynx browser on pangea). Graphical browsers normally can display graphics directly if they are stored in either the GIF or JPEG format. GIF works better for line art; JPEG is better for photographic images. Save GIF image files with the suffix .gif as part of the filename. Save JPEG image files with the suffix .jpeg or .jpg as part of the filename.
The URL can refer to an image file on this same server or another server
somewhere else on the network. An example of a reference to a graphic image on
another site is:
If the file is in the same directory as the text document which references it,
then the URL can consist of just the plain filename without the
"http://..."
part, for example:
An example of the ALT attribute would be the tag:
Finally, you use the <a> tag, in two different forms, to either create a link to another document (or a link to another section of the current document), or to mark sections of your document with "anchors" so links can be made directly to those sections. This tag is used within the BODY section, interspersed with the text.
To create a link to another document
(or to link to another "anchor" within the current document),
use this pair of tags:
These tags enclose a section of text or a graphic image, which then becomes the link. When the user selects (clicks on) any word in the associated text, or on the associated image, then the link is activated and the browser fetches and displays the new page indicated by the link. Browsers usually indicate that a section of text is a link by underlining it and possibly changing the color of the text. A graphic image that is itself a link to another document will be outlined with a colored or dark border. URL-or-anchor refers to either a valid URL on this or any other server, or to an "anchor" mark within the current document, made by the other form of the <a> tag (below). Be sure to enclose it within quotes. The URL syntax is briefly described above in the description of image tags, or in detail on the Uniform Resource Locator web page. The syntax for referring to an anchor within the current document is simply "#anchor-name", that is, precede the anchor name with the hash mark (#).
The other form of the
<a>
tag can be used to create an "anchor"
mark within your document. Use this pair of tags to bracket the text or image
that is to be the anchor:
The "anchor" can be any arbitrary name that you like, such as "section1" or "picture1". The text or graphic image included between the <a> tags in this form becomes the anchor location in the document, and will be displayed at the top of the window when the browser jumps to that location in the document. It is also possible to have a "null" anchor, that is, no text between the tags, in which case the text immediately following appears at the top of the window.
|