Text Formatting with HTML

Character Styles

When you use an HTML tag for paragraphs, headings, or lists, those tags affect that block of text as a whole, changing the font, changing the spacing above and below the line, or adding characters (in the case of bulleted lists). Character styles are tags that affect words or characters within other HTML entities and change the appearance of that text so it is somehow different from the surrounding text - making it bold or underlined, for instance.

To change the appearance of a set of characters within text, you can use one of two kinds of tags: logical styles or physical styles.

Logical Styles

Logical style tags indicate how the given text is to be used, not how it is to be displayed (emphasis, citation, definition). The displaying browser determines how the final display will look. All that you can guarantee is that this text will some how be different than the rest of the text on the page. Here are 8 logical tags:

<EM>
The characters are to be emphasized in some way. In graphical browsers <EM> is typically italic. Example: <P>We'd all get along much better if you'd stop being so <EM>silly<EM></P>

We'd all get along much better if you'd stop being so silly

<STRONG>
More strongly emphasized than <EM>. For example: <P> You <STRONG>must </STRONG>open the can before drinking</P>

You must open the can before drinking

<CODE>
A code sample:<CODE>#include "trans.h"</CODE>

#include "trans.h"

<SAMP>
Example text, similar to <CODE>: <P>The URL for that page is <SAMP>http://www.cern.ch/</SAMP></P>

The URL for that page is http://www.cern.ch/

<KBD>
Text intended to be typed by a user: <P>Type the following command: <KBD>find . -name "prune" -print </KBD></P>

Type the following command: find . -name "prune" -print

<VAR>
The name of a variable, or some entity to be replaced with an actual value. Often displayed as italic or underlined, for example: <P><CODE>chown </CODE><VAR>your_name the_file</VAR></P>

chown your_name the_file

<DFN>
A definition. <DFN> is used to highlight a word that will be defined or has just been defined: <P>Styles that are named after how they are actally used are called <DFN> logical character styles</DFN></P> (Not sure if this is still supported or not.)

Styles that are named after how they are actually used are called logical character styles

<CITE>
A short quote or citation: <P>Eggplant has been known to cause nausea in many unsuspecting people<CITE> (Lemay, 1994)</CITE> </P>

Eggplant has been known to cause nausea in many unsuspecting people (Lemay, 1994)

Physical Styles

Physical Style tags indicate exactly the way text is to be formatted (bold, underlined, etc...). Like Character Style tags, each tag has a beginning and a closing tag. HTML 3.2 defines the following Physical Style tags:
<B>
Bold
<I>
Italic
<TT>
Monospaced typwriter font
<U>
Underlined
<S>
Strike through
<BIG>
Bigger print than the surrounding text
<SMALL>
Smaller print
<SUB>
TextSubscript
<SUP>
TextSuperscript

You may also nest charater tags-for example you may use both Bold and Italic together like this:

This is Bold Italic

Preformatted Text

Normally an HTML browser stripes off extra blank spaces, tabs, returns, etc.. that are in the document. Using the <PRE> and </PRE> retains the formatting around text. The catch is that the text is presented in in monospaced Courier font. You can use tags such as anchors, links, and character styles, but not element tags like headings and paragraphs. Here is an example:

   Unit      Distance  Destination
  ----------------------------------
   Miles     125       Chicago
   Km        300       Detroit

When writing the code, remember that the space used by the tags is ignored. Here is the code:

<PRE>
   Unit      Distance  <I>Destination</I>
  ----------------------------------
   Miles     125       Chicago
   Km        <B>300</B>       Detroit
</PRE>

Notice how the characters in the code do not line up as they do in the final displayed text due to the tags.


Horizontal Rules

The <HR> tag (no closing tag) creats a horizontal line across the page.

The extensions for the <HR>. tage are WIDTH, ALIGN, SIZE and NOSHADE. Here is a table of <HR>'s attributes. Notice that when they are invoked from within a table, they use the tables left margin as the left hand starting point. The first 3 codes are repeated after the table to demonstrate the difference.




Line Breaks

The <BR> tag breaks a line of text at it's location. When a browser encounters a <BR> tag it starts the following text at the left side of the following line. It does not add additional spacing. If used in a table, text resumes at the left edge of the table.
Here are two examples followed by there code:

I am
using
to many
Break tags!

<P>I am <BR> using <BR> to many <BR> Break tags!</P>

A table:


Addresses

The Address tag <ADDRESS> is used for signature-like entities on web pages. They usually go at the bottom of a web page. Here is an example:

[email protected] Donald R Painter

Quotations

The <BLOCKQUOTE> tag is used to create quotations. You may use <BR> tags in it for formatting. For example:

Thunder roared
Lightening flashed
A tree fell
A frog got smashed.

The code:

<BLOCKQUOTE> Thunder roared<BR> Lightening flashed<BR> A tree fell<BR> A frog got smashed. </BLOCKQUOTE>


Special Characters

Characters in HTML files must be from the standard (7-bit) ASCII character set, and cannot include any characters from "extended" (8-bit) ASCII, as every platform has a different definition of the characters that are included in the upper range. HTML browsers interpret codes from upper ASCII as characters in the ISO-Latin-1 (ISO-8859-1) character set, a superset of ASCII.

To make special characters, you must put codes into your page. Here is a list of codes:

 Entity    Result       Note
 ------    ------       -----------
 &lt;         <
 &gt;         >
 &amp;        &
 &quot;       "
 &laquo;      «
 &copy;       ©        copyright
 &reg;        ®        registered trademark
 &acute;      ´        example: resumé  Code: resum&eacute
 &nbsp;                A blank space
 &
 &
 &
 &
 &

Text Alignment

Under HTML 3.2 text can be aligned as LEFT, CENTER, or RIGHT justified. Here are examples of each:

<H3 ALIGN=LEFT>This is aligned LEFT</H3>

This is aligned LEFT

<H3 ALIGN=CENTER>This is aligned CENTER</H3>

This is aligned CENTER

<H3 ALIGN=RIGHT>This is aligned RIGHT</H3>

This is aligned RIGHT

If you have several lines that you want justified in the same way, you can use <DIV> to do them all at once. Just put <DIV> ahead of them and </DIV> at the end of the group like this:

This is the first line

This is the second line

This is the last line

The code looks like this:

<DIV ALIGN=CENTER>
<H2> This is the first line</H2>
<H3> This is the second line</H3>
<H3> This is the last line</H3>
</DIV>


Fonts and Font Size

The <FONT> tag was originally used to control the font size of the characters that it surrounded. It has since been expanded to include changing the font itself as well as the color of the font.

Font Size

Values for the font SIZE attribute are 1 thru 7. 1 being the smallest, 3 the default, and 7 the largest. Here are examples:

Font = 1 , Font = 2 , Font = 3 , Font = 4 , Font = 5 , Font = 6 ,
Font = 7 ,

<FONT SIZE=1>Font = 1 ,</FONT> <FONT SIZE=2>Font = 2 ,</FONT> etc...
Font size can also be used to change the spacing of a blank line between to blocks of text. The space below was put there by setting the FONT SIZE=7 and using the <BR> tag.


Font Face

The FACE attribute gets a list of font faces. The browser starts at the front of the list and looks for that font. It it can not find the first font it searches for the second and so on until it either finds one of the requested fonts or it defaults to the default system font.

<FONT FACE="Futura,Helvetica">Futura is my first choice, Helvetica is my second.</FONT>

Futura is my first choice, Helvetica is my second.


The Dreaded BLINK

This is truely the mark of a poor web page. Anyone using it should be shot before he or she is allowed to reproduce and pollute our gene pool.
Having said that, here it is:

Never use the <BLINK>BLINK</BLINK> command!

Never use the BLINK command!


Other extensions

Special List Formats

To change the type of "bullets" that a browser uses while displaying lists, you can use the TYPE attribute. The attribute is put within the opening tag for the list: <UL TYPE=I> for Roman numerals. Here is a table and an example:

  1. TYPE=1 The default for OL lists
  1. TYPE=A Orders the list with uppercase letters (A, B, C, and so on)
  1. TYPE=a Orders the list with lowercase letters (a, b, c, and so on)
  1. TYPE=I Orders the list with uppercase Roman numerals (I, II, III, IV, and so on)
  1. TYPE=i Orders the list with lowercase Roman numerals (i, ii, iii, iv, and so on)

<NOBR> and <WBR>

<NOBR> ... </NOBR> are tags that force everything between them to be displayed on a single line, even if the line becomes wider than the display screen. <WBR> is used to tell the browser where to break a line at. However, if the line will fit on the display without breaking, the browser will ignore the <WBR> tag.