A Beginner's Guide to HTML Part II: (a brief reference)
Posted: 2002-06-01
By: ArchiveBot
Viewed: 86
Filed Under:
No attachments for this post
You can't get too far in ASP without an intimate knowledge of HTML, so this tutorial will take a newbie through the ABC's of HTML...one step at a time. It's also a great reference for pros who forget how to use little known tags! By pubs@ncsa.uiuc.edu
Original Author: Found on the World Wide Web
Code
URLs The World Wide Web uses Uniform Resource Locators (URLs) scheme://host.domain [:port]/path/ filename where scheme is one of file The port number can generally be omitted. (That means For example, to include a link to this primer in your <A HREF="http://www.ncsa.uiuc.edu/General/Internet/WWW/HTMLPrimer.html"> This entry makes the text NCSA's Beginner's Guide to For more information on URLs, refer to: * WWW Names and Addresses, URIs, URLs, URNs Links to Specific Sections Anchors can also be used to move a reader to a This guide is a good example of using named anchors in You can also link to a specific section in another Links Between Sections of Different Documents Suppose you want to set a link from document A (documentA.html) Enter the HTML coding for a link to a named anchor: documentA.html: In addition to the many state Think of the characters after the hash (#) mark as a tab Next, create the named anchor (in this example "ANP") With both of these elements in place, you can bring a NOTE: You cannot make links to specific sections within Links to Specific Sections within the Current Document The technique is the same except the filename is For example, to link to the ANP anchor from within ...More information about <A HREF="#ANP">Acadia Be sure to include the <A NAME=> tag at the place Named anchors are particularly useful when you think Mailto You can make it easy for a reader to send electronic <A HREF="mailto:emailinfo@host">Name</a> For example, enter: <A HREF="mailto:pubs@ncsa.uiuc.edu">NCSA to create a mail window that is already configured to Most Web browsers can display inline images (that is, To include an inline image, enter: <IMG SRC=ImageName> where ImageName is the URL of the image file. The syntax for <IMG SRC> URLs is identical to that Image Size Attributes You should include two other attributes on <IMG> For example, to include a self portrait image in a file <IMG SRC=SelfPortrait.gif NOTE: Some browsers use the HEIGHT and WIDTH attributes Aligning Images You have some flexibility when displaying images. You Aligning Text with an Image This text is aligned with the top of the And this text is centered on the image Images without Text <p ALIGN=CENTER> which results in: The image is centered; this paragraph starts below it Alternate Text for Images Some World Wide Web browsers--primarily those that run The ALT attribute lets you specify text to be displayed <IMG SRC="UpArrow.gif" where UpArrow.gif is the picture of an upward pointing You should try to include alternate text for each image Background Graphics Newer versions of Web browsers can load an image and use Background images can be a texture (linen finished However you only have to create a small piece of the The tag to include a background image is included in the <BODY BACKGROUND="filename.gif"> Background Color By default browsers display text in black on a gray Always preview changes like this to make sure your pages You change the color of text, links, visited links, and <BODY BGCOLOR="#000000" TEXT="#FFFFFF" This creates a window with a black background (BGCOLOR), The six-digit number and letter combinations represent * ColorPro Web server External Images, Sounds, and Animations You may want to have an image open as a separate To include a reference to an external image, enter: <A HREF="MyImage.gif">link You can also use a smaller image as a link to a larger <A HREF="LargerImage.gif"><IMG The reader sees the SmallImage.gif image and clicks on Use the same syntax for links to external animations and <A HREF="AdamsRib.mov">link specifies a link to a QuickTime movie. Some common file File Type Extension Keep in mind your intended audience and their access to Before HTML tags for tables were finalized, authors had Think of your tabular information in light of the coding Element NOTE: Attributes defined within <TH> ... </TH> * VALIGN (TOP, MIDDLE, BOTTOM) * COLSPAN=n * ROWSPAN=n * NOWRAP General Table Format The general format of a table looks like this: <TABLE> <CAPTION> caption contents </CAPTION> <TR> <TH> cell contents </TH> <TR> <TD> cell contents </TD> <TR> </TABLE> The <TABLE> and </TABLE> tags must surround Tables for Nontabular Information Some HTML authors use tables to present nontabular Using table borders with images can create an impressive Web forms let a reader return information to a Web This processing of incoming data is usually handled by a The forms themselves are not hard to code. They follow Avoid Overlapping Tags Consider this example of HTML: <B>This is an example of <DFN>overlapping</B> The word overlapping is contained within both the In general, avoid overlapping tags. Look at your tags Embed Only Anchors and Character Tags HTML protocol allows you to embed links within other <H1><A HREF="Destination.html">My Do not embed HTML tags within an anchor: <A HREF="Destination.html"> Although most browsers currently handle this second Character tags modify the appearance of the text within <UL> Avoid embedding other types of HTML element tags. For <UL> Although some browsers handle this quite nicely, What's the difference between embedding a <B> Character formatting tags also are generally not <B><I>some would produce bold-italic text. On some browsers it Do the Final Steps Validate Your Code When you put a document on a Web server, be sure to You can run your coded files through an HTML validation Dummy Images When an <IMG SRC> tag points to an image that does Update Your Files If the contents of a file are static (such as a Updating is particularly important when the file Browsers Differ Web browsers display HTML elements differently. Remember You could spend a lot of time making your file Commenting Your Files You might want to include comments in your HTML files. Comments such as the name of the person updating a file, To include a comment, enter: <!-- your comments here --> You must include the exclamation mark and the hyphens as This guide is only an introduction to HTML, not a Style Guides The following offer advice on how to write * Composing Good HTML
to specify the
location of files on other servers. A URL includes the type of resource
being accessed (e.g., Web, gopher, WAIS), the address of the server, and the
location of the file. The syntax is:
a file on your local system
ftp a file on an anonymous FTP server
http
a file on a World Wide Web server
gopher
a file on a Gopher server
WAIS
a file on a WAIS server
news
a Usenet newsgroup
telnet
a connection to a Telnet-based service
unless someone tells
you otherwise, leave it out.)
document, enter:
NCSA's Beginner's Guide to HTML</A>
HTML a hyperlink to
this document.
* A Beginner's Guide to URLs
particular section in a
document (either the same or a different document) rather than to the top,
which is the default. This type of an anchor is commonly called a named
anchor because to create the links, you insert HTML names within the
document.
one document. The
guide is constructed as one document to make printing easier. But as one
(long) document, it can be time-consuming to move through when all you
really want to know about is one bit of information about HTML. Internal
hyperlinks are used to create a "table of contents" at the top of this
document. These hyperlinks move you from one location in the document to
another location in the same document. (Go to the top of this document and
then click on the Links to Specific Sections hyperlink in the table of
contents. You will wind up back here.)
document. That
information is presented first because understanding that helps you
understand linking within one document.
to a
specific section in another document (MaineStats.html).
parks, Maine is also home to
<a href="MaineStats.html#ANP">Acadia
National Park</a>.
within the
MaineStats.html file. This tab tells your browser what should be displayed
at the top of the window when the link is activated. In other words, the
first line in your browser window should be the Acadia National Park
heading.
in MaineStats.html:
tml:
<H2><A NAME="ANP">Acadia
National Park</a></H2>
reader directly to the
Acadia reference in MaineStats.html.
a different document
unless either you have write permission to the coded source of that document
or that document already contains in-document named anchors. For example,
you could include named anchors to this primer in a document you are writing
because there are named anchors in this guide (use View Source in your
browser to see the coding). But if this document did not have named anchors,
you could not make a link to a specific section because you cannot edit the
original file on NCSA's server.
omitted.
MaineStats, enter:
National Park</a>
is available elsewhere in this document.
in your document where you
want the link to jump to (<H2><A NAME="ANP">Acadia
National Park</a></H2>).
readers will print a
document in its entirety or when you have a lot of short information you
want to place online in one file.
mail to a specific
person or mail alias by including the mailto attribute in a hyperlink. The
format is:
Publications Group</a>
open a mail window for
the NCSA Publications Group alias. (You, of course, will enter another mail
address!)
Inline Images
images next to text)
that are in X Bitmap (XBM), GIF, or JPEG format. Other image formats are
being incorporated into Web browsers [e.g., the Portable Network Graphic
(PNG) format]. Each image takes time to process and slows down the initial
display of a document. Carefully select your images and the number of images
in a document.
used in an anchor HREF.
If the image file is a GIF file, then the filename part of ImageName must
end with .gif. Filenames of X Bitmap images must end with .xbm; JPEG image
files must end with .jpg or .jpeg; and Portable Network Graphic files must
end with .png.
tags to tell your browser
the size of the images it is downloading with the text. The HEIGHT and WIDTH
attributes let your browser set aside the appropriate space (in pixels) for
the images as it downloads the rest of the file. (Get the pixel size from
your image-processing software, such as Adobe Photoshop.)
along with the
portrait's dimensions, enter:
HEIGHT=100 WIDTH=65>
to stretch or shrink
an image to fit into the allotted space when the image does not exactly
match the attribute numbers. Not all browser developers think
stretching/shrinking is a good idea. So don't plan on your readers having
access to this feature. Check your dimensions and use the correct ones.
can have images
separated from text and aligned to the left or right or centered. Or you can
have an image aligned with text. Try several possibilities to see how your
information looks best.
By default the bottom of an image is aligned with the following
text, as
shown in this paragraph. You can align images to the top or center of a
paragraph using the ALIGN= attributes TOP and CENTER.
image (<IMG SRC =
"BarHotlist.gif" ALIGN=TOP>). Notice how the browser aligns only
one line
and then jumps to the bottom of the image for the rest of the text.
(<IMG SRC = "BarHotlist.gif"
ALIGN=CENTER>). Again, only one line of text is centered; the rest is below
the image.
To display an image without any associated text (e.g., your organization's
logo), make it a separate paragraph. Use the paragraph ALIGN= attribute to
center the image or adjust it to the right side of the window as shown
below:
<IMG SRC = "BarHotlist.gif">
</p>
and left justified.
on VT100
terminals--cannot display images. Some users turn off image loading even if
their software can display images (especially if they are using a modem or
have a slow connection). HTML provides a mechanism to tell readers what they
are missing on your pages.
instead of an image.
For example:
ALT="Up">
arrow. With
graphics-capable viewers that have image-loading turned on, you see the up
arrow graphic. With a VT100 browser or if image-loading is turned off, the
word Up is shown in your window.
you use in your
document, which is a courtesy for your readers.
it as a background
when displaying a page. Some people like background images and some don't.
In general, if you want to include a background, make sure your text can be
read easily when displayed on top of the image.
paper, for example) or an
image of an object (a logo possibly). You create the background image as you
do any image.
image. Using a feature
called tiling, a browser takes the image and repeats it across and down to
fill your browser window. In sum you generate one image, and the browser
replicates it enough times to fill your window. This action is automatic
when you use the background tag shown below.
<BODY> statement as
an attribute:
background. However, you
can change both elements if you want. Some HTML authors select a background
color and coordinate it with a change in the color of the text.
are readable. (For
example, many people find red text on a black background difficult to read!)
active links using
attributes of the <BODY> tag. For example, enter:
LINK="#9690CC">
white text (TEXT),
and silvery hyperlinks (LINK).
colors by giving
their RGB (red, green, blue) value. The six digits are actually three
two-digit numbers in sequence, representing the amount of red, green, or
blue as a hexadecimal value in the range 00-FF. For example, 000000 is black
(no color at all), FF0000 is bright red, and FFFFFF is white (fully
saturated with all three colors). These number and letter combinations are
cryptic. Fortunately an online resource is available to help you track down
the combinations that map to specific colors:
document when a user
activates a link on either a word or a smaller, inline version of the image
included in your document. This is called an external image, and it is
useful if you do not wish to slow down the loading of the main document with
large inline images.
anchor</A>
image. Enter:
SRC="SmallImage.gif"></A>
it to open the
LargerImage.gif file.
sounds. The only
difference is the file extension of the linked file. For example,
anchor</A>
types and their
extensions are:
plain text .txt
HTML document .html
GIF image .gif
TIFF image .tiff
X Bitmap image .xbm
JPEG image .jpg or .jpeg
PostScript file .ps
AIFF sound file .aiff
AU sound file .au
WAV sound file .wav
QuickTime movie .mov
MPEG movie .mpeg or .mpg
software. Most UNIX
workstations, for instance, cannot view QuickTime movies.
Tables
to carefully format
their tabular information within <PRE> tags, counting spaces and
previewing
their output. Tables are very useful for presentation of tabular information
as well as a boon to creative HTML authors who use the table tags to present
their regular Web pages. (Check out the NCSA Relativity Group's pages for an
excellent, award-winning example.)
explained below. A
table has heads where you explain what the columns/rows include, rows for
information, cells for each item. In the following table, the first column
contains the header information, each row explains an HTML table tag, and
each cell contains a paired tag or an explanation of the tag's function.
Table Elements
Description
<TABLE> ... defines a table in HTML. If the BORDER
attribute is
</TABLE> present, your browser
displays the table with a border.
<CAPTION> ... defines the caption for the title of the table. The
default
</CAPTION> position of the title is centered at
the top of the table.
The attribute ALIGN=BOTTOM can be used to position the
caption below the table.
NOTE: Any kind of markup tag can be used in the caption.
<TR> ... </TR> specifies a table row within a table. You may define
default attributes for the entire row: ALIGN (LEFT, CENTER,
RIGHT) and/or VALIGN (TOP, MIDDLE, BOTTOM). See Table
Attributes at the end of this table for more information.
<TH> ... </TH> defines a table header cell. By default the text in
this
cell is bold and centered. Table header cells may contain
other attributes to determine the characteristics of the
cell and/or its contents. See Table Attributes at the end
of this table for more information.
<TD> ... </TD> defines a table data cell. By default the text in
this cell
is aligned left and centered vertically. Table data cells
may contain other attributes to determine the
characteristics of the cell and/or its contents. See Table
Attributes at the end of this table for more information.
Table Attributes
or <TD> ... </TD> cells
override the default alignment set in a <TR> ... </TR>.
Attribute
Description
* ALIGN (LEFT, CENTER, RIGHT)
* Horizontal alignment of a cell.
* Vertical alignment of a cell.
* The number (n) of columns a cell spans.
* The number (n) of rows a cell spans.
* Turn off word wrapping within a cell.
<== start of table definition
<== caption definition
<== start of first row definition
<TH> cell contents </TH>
<== first cell in row 1 (a head)
<== last cell in row 1 (a head)
</TR>
<== end of first row definition
<== start of second row definition
<TD> cell contents </TD>
<== first cell in row 2
<== last cell in row 2
</TR>
<== end of second row definition
<== start of last row definition
<TD> cell contents </TD>
<== first cell in last row
...
<TD> cell contents </TD>
<== last cell in last row
</TR>
<== end of last row definition
<== end of table definition
the entire table definition. The
first item inside the table is the CAPTION, which is optional. Then you can
have any number of rows defined by the <TR> and </TR> tags. Within a
row you
can have any number of cells defined by the <TD>...</TD> or <TH>...</TH>
tags. Each row of a table is, essentially, formatted independently of the
rows above and below it. This lets you easily display tables like the one
above with a single cell, such as Table Attributes, spanning columns of the
table.
information. For example,
because links can be included in table cells, some authors use a table with
no borders to create "one" image from separate images. Browsers that
can
display tables properly show the various images seamlessly, making the
created image seem like an image map (one image with hyperlinked quadrants).
display as well.
Experiment and see what you like.
Fill-out Forms
server for some action.
For example, suppose you collect names and email addresses so you can email
some information to people who request it. For each person who enters his or
her name and address, you need some information to be sent and the
respondent's particulars added to a data base.
script or program
written in Perl or another language that manipulates text, files, and
information. If you cannot write a program or script for your incoming
information, you need to find someone who can do this for you.
the same constructs
as other HTML tags. What could be difficult is the program or script that
takes the information submitted in a form and processes it. Because of the
need for specialized scripts to handle the incoming form information,
fill-out forms are not discussed in this primer. Check the Additional Online
Reference section for more information.
Troubleshooting
HTML tags.</DFN>
<B> and <DFN> tags. A
browser might be confused by this coding and might not display it the way
you intend. The only way to know is to check each popular browser (which is
time-consuming and impractical).
and try pairing them
up. Tags (with the obvious exceptions of elements whose end tags may be
omitted, such as paragraphs) should be paired without an intervening tag in
between. Look again at the example above. You cannot pair the bold tags
without another tag in the middle (the first definition tag). Try matching
your coding up like this to see if you have any problem areas that should be
fixed before your release your files to a server.
HTML tags:
heading</A></H1>
<H1>My heading</H1>
</A>
example, the official
HTML specifications do not support this construct and your file will
probably not work with future browsers. Remember that browsers can be
forgiving when displaying improperly coded files. But that forgiveness may
not last to the next version of the software! When in doubt, code your files
according to the HTML specifications (see For More Information below).
other elements:
<LI><B>A bold list item</B>
<LI><I>An italic list item</I>
</UL>
example, you might be
tempted to embed a heading within a list in order to make the font size
larger:
<LI><H1>A large heading</H1>
<LI><H2>Something slightly smaller</H2>
</UL>
formatting of such coding
is unpredictable (because it is undefined). For compatibility with all
browsers, avoid these kinds of constructs. (The Netscape <FONT> tag, which
lets you specify how large individual characters will be displayed in your
window, is not currently part of the official HTML specifications.)
within a <LI> tag as opposed
to embedding a <H1> within a <LI>? Within HTML the semantic meaning
of <H1>
is that it's the main heading of a document and that it should be followed
by the content of the document. Therefore it doesn't make sense to find a
<H1> within a list.
additive. For example, you
might expect that:
text</I></B>
does; other browsers
interpret only the innermost tag.
check the formatting and
each link (including named anchors). Ideally you will have someone else read
through and comment on your file(s) before you consider a document finished.
service that will
tell you if your code conforms to accepted HTML. If you are not sure your
coding conforms to HTML specifications, this can be a useful teaching tool.
Fortunately the service lets you select the level of conformance you want
for your files (i.e., strict, level 2, level 3). If you want to use some
codes that are not officially part of the HTML specifications, this latitude
is helpful.
not exist, a dummy image
is substituted by your browser software. When this happens during your final
review of your files, make sure that the referenced image does in fact
exist, that the hyperlink has the correct information in the URL, and that
the file permission is set appropriately (world-readable). Then check online
again!
biography of George
Washington), no updating is probably needed. But for documents that are time
sensitive or covering a field that changes frequently, remember to update
your documents!
contains information such
as a weekly schedule or a deadline for a program funding announcement.
Remove out-of-date files or note why something that appears dated is still
on a server (e.g., the program requirements will remain the same for the
next cycle so the file is still available as an interim reference).
that not all codes
used in HTML files are interpreted by all browsers. Any code a browser does
not understand is usually ignored though.
"look perfect" using your
current browser. If you check that file using another browser, it will
likely display (a little or a lot) differently. Hence these words of advice:
code your files using correct HTML. Leave the interpreting to the browsers
and hope for the best.
Comments in HTML are
like comments in a computer program--the text you enter is not used by the
browser in any formatting and is not directly viewable by the reader just as
computer program comments are not used and are not viewable. The comments
are accessible if a reader views the source file, however.
the software and
version used in creating a file, or the date that a minor edit was made are
the norm.
shown.
For More Information
comprehensive reference.
Below are additional online sources of information. Remember to check a
bookstore near you for Web and HTML books.
"good" HTML:
* W3C's style guide for online hypertext
Comments on this post
No comments have been added for this post.
You must be logged in to make a comment.