Linking
The chief power of HTML comes from its ability to link text and/or an image to another document or section of a document. A browser highlights the identified text or image with color and/or underlines to indicate that it is a hypertext link (often shortened to hyperlink or link).HTML's single hypertext-related tag is <A>, which stands for anchor. To include an anchor in your document:
- start the anchor with <A (include a space after
the
A) - specify the document you're linking to by entering the parameter HREF="filename" followed by a closing right angle bracket (>)
- enter the text that will serve as the hypertext link in the current document
- enter the ending anchor tag: </A> (no space is needed before the end anchor tag)
Here is a sample hypertext reference in a file called US.html:
<A HREF="MaineStats.html">Maine</A>
This entry makes the word Maine the hyperlink to the document MaineStats.html, which is in the same directory as the first document.
Relative Pathnames Versus Absolute Pathnames
You can link to documents in other directories by specifying the relative path from the current document to the linked document. For example, a link to a file NYStats.html located in the subdirectory AtlanticStates would be:
<A HREF="AtlanticStates/NYStats.html">New York</A>
These are called relative links because you are specifying the path to the linked file relative to the location of the current file. You can also use the absolute pathname (the complete URL) of the file, but relative links are more efficient in accessing a server.
Pathnames use the standard UNIX syntax. The UNIX syntax for the parent directory (the directory that contains the current directory) is "..". (For more information consult a beginning UNIX reference text such as Learning the UNIX Operating System from O'Reilly and Associates, Inc.)
If you were in the NYStats.html file and were referring to the original document US.html, your link would look like this:
<A HREF="../US.html">United States</A>
In general, you should use relative links because:
- it's easier to move a group of documents to another location (because the relative path names will still be valid)
- it's more efficient connecting to the server
- there is less to type
However use absolute pathnames when linking to documents that are not directly related. For example, consider a group of documents that comprise a user manual. Links within this group should be relative links. Links to other documents (perhaps a reference to related software) should use full path names. This way if you move the user manual to a different directory, none of the links would have to be updated.
URLs
The World Wide Web uses Uniform Resource Locators (URLs) 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:
scheme://host.domain [:port]/path/ filename
where scheme is one of
- file
- 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
The port number can generally be omitted. (That means unless someone tells you otherwise, leave it out.)
For example, to include a link to this guide in your document, enter:
<A HREF="http://osu.orst.edu/admin/web-edit/html/"> Web Editors' Companion Guide</A>
This entry makes the text Web Editors' Companion Guide a hyperlink to this document.
For more information on URLs, refer to:
Links to Specific Sections
Anchors can also be used to move a reader to a 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.
This guide is a good example of using named anchors in 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 Companion Guide document and then click on the Links to Specific Sections hyperlink in the table of contents. You will wind up back here.)
You can also link to a specific section in another document. That information is presented first because understanding that helps you understand linking within one document.
Links Between Sections of Different Documents
Suppose you want to set a link from document A (documentA.html) to a specific section in another document (MaineStats.html).Enter the HTML coding for a link to a named anchor:
documentA.html:
In addition to the many state parks, Maine is also home to
<a href="MaineStats.html#ANP">Acadia National Park</a>.
Think of the characters after the hash (#) mark as a tab 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.
Next, create the named anchor (in this example "ANP") in MaineStats.html:
<H2><A NAME="ANP">Acadia National Park</a></H2>With both of these elements in place, you can bring a reader directly to the Acadia reference in MaineStats.html.
NOTE: You cannot make links to specific sections within 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.
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 MaineStats, enter:
...More information about
<A HREF="#ANP">Acadia National Park</a>
is available elsewhere in this document.
Be sure to include the <A NAME=> tag at the
place in your document
where you want the link to jump to (<H2><A
NAME="ANP">Acadia National Park</a></H2>).
Named anchors are particularly useful when you think 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.
Mailto
You can make it easy for a reader to send electronic mail to a specific person or mail alias by including the mailto attribute in a hyperlink. The format is:
<A HREF="mailto:emailinfo@host">Name</a>For example, enter:
<A HREF="mailto:web@mail.orst.edu"> Webworks Staff Support</a>to create a mail window that is already configured to open a mail window for the Webworks Staff Support alias. (You, of course, will enter another mail address!)
Inline Images
Most Web browsers can display inline images (that is, 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.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 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.
Image Size Attributes
You should include two other attributes on <IMG> 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.)For example, to include a self portrait image in a file along with the portrait's dimensions, enter:
<IMG SRC=SelfPortrait.gif HEIGHT=100 WIDTH=65>
NOTE: Some browsers use the HEIGHT and WIDTH attributes 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 s tretching/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.
Aligning Images
You have some flexibility when displaying images. You 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.
Aligning Text with an Image
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.
Images without Text
Some World Wide Web browsers--primarily those that run 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.
The ALT attribute lets you specify
text to be displayed instead of an image. For example:
where UpArrow.gif is the picture of an upward pointing
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 should try to include alternate text for each image you use
in your document, which
is a courtesy for your readers.
Background images can be a texture (linen finished paper, for example) or an
image of an object (a logo possibly).
You create the background image
as you do any image.
However you only
have to create a small
piece of the 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.
The tag to include a background image is included in
the <BODY>
statement as an attribute:
Always preview changes like
this to make sure your
pages are readable. (For example, many people find red text on a black
background difficult to read!)
You change the color of text, links, visited links, and active links
using attributes of the <BODY> tag. For example, enter:
The six-digit number and letter combinations represent 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 and there is software available for you to do this on
your workstation:
You may want to have an image open as a separate 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.
To include a reference to an external image, enter:
Use the same syntax for links to external animations and sounds.
The only difference is the file extension of the linked file. For example,
<A HREF="AdamsRib.mov">link anchor</A>
specifies a link to a QuickTime movie. Some common file types and their
extensions are:
Keep in mind your intended audience and their access to software. Most UNIX
workstations, for instance, cannot view QuickTime movies.
This text is aligned with the top of the image (<IMG SRC="/example.gif" alt = "This is an example picture" ALIGN=TOP><
/samp>). Notice how
the browser aligns only one line and then jumps to the bottom of the image for
the rest of the text.
And this text is centered on
the image (<IMG SRC="/example.gif" alt="This is an example picture" 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:
<p ALIGN=CENTER>
<IMG SRC = "/example.gif">
</p>
which results in:
Alternate Text for Images
<IMG SRC="UpArrow.gif" ALT="Up">
Background Graphics
Newer versions of Web browsers can load an image and use 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.
<BODY BACKGROUND="filename.gif">
Background Color
By default browsers display text in black on a gray 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.
<BODY BGCOLOR="#000000" TEXT="#FFFFFF" LINK="#9690CC">
This creates a window with a black background (BGCOLOR), white text
(TEXT), and silvery hyperlinks (LINK).
External Images, Sounds, and Animations
<A HREF="MyImage.gif">link anchor</A>
You can also use a smaller image as a link to a larger image. Enter:
<A HREF="LargerImage.gif"><IMG SRC="SmallImage.gif"></A>
The reader sees the SmallImage.gif image and clicks on it to
open the LargerImage.gif file.
File Type
Extension
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




