CSCI 220: HTML Authoring & WWW Programming
Basic HTML Formatting
A note about editors
There are a number of fine programs available to help you write
html documents. We will allow (in fact encourage) you to use an editor
if it will help you. However, use of such editors is not
an alternative to using the tags. We will concentrate on the code that
can be created with any text editor in any environment. If you learn
the tags this way, you will be prepared to deal with any editor
available. My personal preference is a straight text editor with
a macro language, but again, the editor doesn't really matter as much
as the problem - solving ideas. For now, stick to something you know,
like pico.
Terminology
- Tags = An HTML "command"
Three components:
- Left angle bracket: <
- The command itself: br
- Right angle bracket: >
Example:<br>
- Containers = pair of tags (opening & closing) which contain an item or items subject to the command
Three componenets:
- Opening tag: <h1>
- Contained items: blah blah blah
- Closing tag: </h1>
Putting these together, we get: <h1>blah blah blah</h1>
- HTML commands are not case sensitive, <BR> and <br> mean the same thing.
The Bare Essentials
The "Bare-bones" HTML document:
- <html></html> = Denotes the entire html file
- <head></head> = The "header" of the document
Example: JavaScript functions are defined here
See also pp. 53-58 of the book
- <title></title> = The title displayed in the title bar of the browser
Also defines what your page will be called if someone bookmarks it
- <body></body> = the body of your document (e.g. your main HTML file)
Thus, our "bare-bones" HTML document might look something like this:
<html>
<head>
<title>
</title>
</head>
<body>
</body>
</html>
Stylistic Note: Keep the opening and closing tags on separate lines to improve readability.
You might want to create a "template" document containing just these tags as a starting point for creating any new web document.
Line Breaks
Commands telling the browser to start the subsequent text on a new line. Just hitting Return/Enter won’t do it (unless you use the <pre></pre> tags, but more on that later), you need to specifically tell the browser "I want to go to a new line". They are single tag commands, not containers. Thus they apply until a subsequent command (such as another break) supersedes them.
- Line breaks:
- <br> => Standard (takes you to the next line)
- <p> => Paragraph (breaks two lines)
- <hr> => Horizontal rule = Inserts a horizontal line across the screen
Several optional attributes which you can set:
- size = x
- width = x
- align = x
- noshade
Examples: <hr size = 5 align = left noshade>
Fonts
There’s a difference between the font preferences which you set in your browser and the
<font></font> HTML tags.
<font></font> allows you to set two attributes:
- Size => Lets you adjust the size of the font
Two kinds:
- Absolute = range of values between 1 - 7 (default is 3)
<font size = 5></font>
- Relative = makes the new font larger or smaller relative to the base font
Increment with + (larger) or - (smaller)
<font size = -2></font> (Makes new font size 1)
- Color => Lets you set the color of the text being displayed (default is black)
Must use hex codes: a string of six hexadecimal digits (0 - 9 & a - f) preceded by #
Example:<font color = #ffffff></font>
Less-frequently used coding system of three numbers between 0 & 255:
255, 255, 255 = white
0, 0, 0 = black
Headings
Boldfaced text which acts as a heading for a section of a document.
Syntax:
<hx></hx> where x is a value between 1 and 6 (1 creates largest heading & 6 smallest)
Alignment (left,right, center) can also be specified
<h3 align = center></h3>
Highlighting
HTML supports three types of text highlighting (besides headings):
- Bold
Physical: <b></b>
Logical: <strong></strong>
- Italic
Physical: <i></i>
Logical: <em></em>
- Underline => <u></u>
Logical styles "configure themselves" to user’s browser settings: (i.e. <strong> does not necessarily have to be bold if the user doesn’t want it to be). See p.70 of the text for a list of other logical styles.
Justification
Center => <center></center>
Backgrounds
Background colors & images give pages "personality" & variety.
Set in the <body> tag:
- Background Color: <body bgcolor = #xxxxxx>
As with font colors, background colors are set with hexadecimal or 0-255 codes
Example: <body bgcolor = #ffffff> => all white background
- Background Image: <body background = image_url>
Example: <body background = "./images/background.gif">
Two main ways to obtain background images for your pages:
- Download them
- "Grab" the image with your browser (actually, for background images, this only works on MS Internet Explorer)
- Provide a hypertext link to an image (not recommended) - it’s slow & unreliable.
Lists
HTML provides several means of creating lists to suit your particular needs:
- Ordered (outline format)
You can create an outline just as you would in a word processor, with capital & lowercase Roman Numerals, capital & lowercase letters & decimal digits.
Basic syntax:
<ol type = x> (where x is one of the five list types)
<li>
</ol>
Ordered list types that can be declared are as follows:
- type = A
- type = a
- type = I
- type = i
- type = 1
If you want to start at some place other than the first value (e.g. 4), use the additional start = x syntax:
<ol type = 1 start = 4>
You can "nest" list types to create a list that looks like:
- Topic 1
- Sub-topic 1
- Sub-topic 2
- Item 1
- Topic 2
- Unordered (bullet points)
Probably the most common type of list that you will see on web pages. The syntax is straightforward & they offer a simple way of highlighting a sequence of individual items.
<ul> => unordered list opening tag
<li> => list item
</ul> => closing tag
You can also specify any of the following bullet types:
- Filled Circles
- Filled Squares
- Unfilled Squares
- Definition (allows you to set a title & then indent the definition)
Again the syntax is pretty straightforward:
<dl> => definition list opening tag
<dt> => the definition title
<dd> => the definition itself ("definition data")
</dl> => definition list closing tag
- Menu =>
- Directory =>
Special Commands
- <pre></pre> => Preformatted text
Allows you to display text "as-is"
- <blockquote></blockquote>
Lets you create an indented paragraph
- Need to use special characters for HTML reserved-characters
&ltp&rt will display <p>
Nesting Commands
A good example is the "bare-bones" HTML document itself. The head, title and body tags are said to be "nested" within
the html tags.
Allows us to perform multiple commands upon an item or series of items in an HTML document. It is generally a good idea
to indent each subsequent container to enhance readability. List tags inherently possess some "automatic formatting"
qualities which can cause conflicts (& pretty bizarre results) if used improperly. When nesting lists within lists, try too
localize the list definitions as much as possible. If you are going to insert a bulleted list somewhere in an ordered list,
define the bulleted list at it’s location in the document.
Lab Assignment
Create a resume for yourself using html markups.
Use the following guidelines:
- The resume should be about one printed page long
- (use the print preview feature of Netscape to guess)
- Use whichever markup tags are appropriate. At a minimum:
- All the basics (title, header, body, and html tags)
- More than one header style
- At least one list
- At least one example of one of bold, emphasis, or italics
- A background color (doesn't matter what)
- At least one horizontal rule
- This does not have to be an accurate resume.
You can change the actual text later
- Besides the guidelines above don't put things there just to put
them there. Use what you need to solve the problem
- Make it look nice
- Create the document with a text editor
(pico, the openwin editor, whatever) and check it with Netscape.
- Save the document as resume.html on your public_html subdirectory
- Be sure it has the appropriate permissions (644)
- When checking your code, save it in the editor, then reload it in
the browser
Most importan of all,
Have FUN!!
More Information
© 1996, Ted D. Biggs, Dept. of Computer and Information Science,
Indiana University, Purdue University, Indianapolis
email: tbiggs@klingon.iupucs.iupui.edu