Lab 3
Page 5


Formatting Text


Regular Text and Paragraphs

The vast majority of many web pages, including this one, is just plain text. So long as you keep a few important rules in mind, you can simply type text into the BODY section of your file, save it, and that text will be displayed on the web page.

Most importantly, HTML browsers ignore all "white space". They do not pay attention to how many spaces you've put between two words, or whether those words are on different lines. All consecutive blank lines, empty spaces and returns are condensed into a single space.

One side effect is that you cannot end a paragraph or create a blank line without typing in a special tag. For example, the text in the following example is broken onto many lines with many spaces, but is not displayed that way:

What you write in HTML How it appears on your web page
The     cat   sat,

on   the
  mat.
The cat sat, on the mat.

While at first this may seem annoying, it is actually very useful. Thanks to this strange feature, you can use blank lines, tabs, and spaces to make your HTML code look neat without worrying about these lines showing up on your actual page.

Of course there will be many occasions when you actually want blank lines and the following tags may help:

Take a look at the following example

What you write in HTML How it appears on your web page
<p>Not too many freshmen know the Alma Mater song.
Even fewer know that it can be sung to the tune
of Gilligan's Island.</p>
Tune every heart and every voice<br>
Bid every care withdraw<br>

Not too many freshmen know the Alma Mater song. Even fewer know that it can be sung to the tune of Gilligan's Island.

Tune every heart and every voice,
Bid every care withdraw

Notice how everything seems neater on the right side. If you use paragraph tags properly, all of your text should come out as nicely, even if the HTML file is messy.

  1. Underneath the <BODY> tag, type in a few paragraphs about yourself, with a <P> at the beginning of each paragraph and a </P> at each end.
  2. Try using a few <BR> tags to create extra blank lines or force your lines to break at specific places.

It is important to note that there are several symbols which HTML will not display properly. If ever your web page is not displaying correctly, make sure you haven't used any of the following symbols.

Symbol Bad Side Effect Special Escape Code
">"
(greater than)
Usually nothing, but sometimes
your browser may misbehave
&gt;
"<"
(less than)
Nothing will be displayed until the next tag &lt;
"&"
(ampersand)
Usually nothing, but sometimes
your browser may misbehave
&amp;

There are, of course, other symbols which cause trouble. Still others are not found on the keyboard and so are difficult to include. The strange-looking codes in the rightmost column above are called "escape codes" and are used to represent these difficult characters. There are many pages on the Web with complete lists of these escape codes.

Here is one more common example of an escape code:

What you write in HTML How it appears on your web page
Copyright &copy; 1997 Copyright © 1997

Headings

You will often want to include headings in your web pages with larger and bolder text that stands out from the page. For this, we have the <H#> </H#> tags. Simply replace "#" with a number from 1-6 and surround your heading wit h these two tags. The text inside will be bold, usually larger (depending on the number -- H1 is the largest), and surrounded by empty lines.

Here's an example of the different levels of headings:

What you write in HTML How it appears on your web page
<H1>This is an H1 heading.</H1>
<H2>This is an H2 heading.</H2>
<H3>This is an H3 heading.</H3>
<H4>This is an H4 heading.</H4>
<H5>This is an H5 heading.</H5>
<H6>This is an H6 heading.</H6>

This is an H1 heading.

This is an H2 heading.

This is an H3 heading.

This is an H4 heading.

This is an H5 heading.
This is an H6 heading.

Always be sure to close your header tag (using the appropriate ending tag) or the rest of your page will be displayed in the larger, bolder text. It is very important that you use an ending tag that matches your opening tag. If you opened with <H2>, you must close with </H2>.

  1. Create a title for your page by placing the following line right under the <BODY> tag.
      <H1>My Name's Web Page</H1>
  2. Right before the paragraphs you wrote in the last section, put in an H2 header that describes it (such as "All about me").

Fancier Text

Now that you know how to display normal text, paragraphs and headings, it's time to get a little bit fancier. Using just a few tags, we can make that text bolder, italicized, underlined, bigger, smaller or even a different color.

Notice how the following tags work:

The Tag What you write in HTML How it appears on your web page
<B></B> <B>This tag makes text bold!</B> This tag makes text bold!
<I></I> <I>This tag italicizes text!</I> This tag italicizes text!
<U></U> <U>This tag underlines text!</U> This tag underlines text!
<TT></TT> <TT>Here's some fixed width text!</TT> Here's some fixed width text!

Of course, the best ways to make something stand out are c o l o r and s i z e!

For this, we use the <font> </font> tags. Inside this tag, you can specify a color, a size, or both in the following way:

What you write in HTML How it appears on your web page
<FONT COLOR = "blue">This is blue text!</FONT> This is blue text!
<FONT SIZE = 5>This is big text!</FONT> This is big text!
<FONT COLOR = "red" SIZE = 6>This is really big, red text!</FONT> This is really big, red text!

The color you use should be one from the table provided on the last page (as background colors for your BODY tag). The size can range from 1-7 with 1 the smallest and 7 being very, very large.

  1. Change the color of the title heading you created on your page
  2. Change the size of that title to be even larger than the H1 tag makes it (by using SIZE=7).

Other Tricks with Text

Bars - In several places on this page, you've probably noticed the horizontal bars stretching across the screen. You can include these bars in your page by simply typing <HR> at each place where you would like one to appear. Like <BR>, <HR> does not require a closing tag since it is an instantaneous effect.

Alignment - There may be times when you would like to center a heading, or right-justify a paragraph. This is easily done by using one of the following two methods:

Pre-formatted Text - If you simply cannot find a way to make your text appear correctly, you can always resort to using the <PRE> </PRE> tags. Any text placed between these two tags will appear exactly as you type it, including spaces, indentation and empty lines. Try not to use it very o ften, however, since the text will appear in a fixed-width font, will not flow naturally, and won't wrap at the edge of your window.

  1. Center your title using either the <CENTER> </CENTER> tags or the ALIGN attribute in the header tag.
  2. Place a bar underneath it by typing <HR> on the line below your title.

What you've done so far

At this point, you should have a web page that looks something like the one below. Don't forget to save your file and load it in Netscape to see what it looks like as often as you like. If you don't understand one of the tags we've used below, or something is wrong with your web page, ask a TA for assistance.

What you write in HTML
<HTML>

<HEAD>
<TITLE>
My Fabulous Web Page </TITLE>
</HEAD>

<BODY BGCOLOR="white" TEXT="black">
<H1 ALIGN=CENTER><FONT COLOR=BLUE SIZE=7>My Web Page</FONT></H1>
<HR>
<BR>
<H2>
All About Me</H2>
<P>
Hi. I'm a student in COS 111 at Princeton University. Studying takes up most of my day, but in my spare time I like to solve crossword puzzles and play the viola.</P>
<P>
Right now I'm learning how to make web pages so that I can go work for AOL and make millions.</P>
</BODY>

</HTML>

How it looks on your web page

My Web Page



All About Me

Hi. I'm a student in COS 111 at Princeton University. Studying takes up most of my day, but in my spare time I like to solve crossword puzzles and play the viola.

Right now I'm learning how to make web pages so that I can go work for AOL and make millions.

If your page looks similar and you understand everything so far, go on to learn about lists, images, links, and sound.


PREVIOUS 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 NEXT