This lesson introduces a number of basic tags that allow a HTML page to be formatted - much in the same way that word processors format documents. The following topics are covered:
Character Formatting
Paragraphs
Paragraph Alignment
Forced Line Breaks
Spaces
Horizontal Rules
Character Formatting:
HTML Code:
This text is <B>bold!</B>
This text is <I>italicized.</I>
This text is <U>underlined</U>
Browser Display:
This text is
bold!
This text is
italicized.
This text is
underlined.
Paragraphs
In HTML you indicate paragraphs with the <P> and </P> elements. Without these elements the document becomes one long paragraph. Likewise, browsers ignore any indentations or blank lines in the HTML code.
Thus the examples below, although coded differently, are all displayed the same way:
HTML Code
<P> This is a very short paragraph to illustrate my point.</P> <P>And this is the second paragraph.</P>
<P> Although this
is written differently
with lots of carriage returns
it still only displays
the paragraphs when
you put in the Paragraph
Tag.</P> <P> Like so.</P>
Browser Display
This is a very short paragraph to illustrate my point.
And this is the second paragraph.
Although this is written differently with lots of carriage returns it still only displays the paragraphs when you put in the Paragraph Tag.
Like so:
NOTE: The </P> closing tag may be omitted. This is because browsers understand that when they encounter a <P> tag, it means that the previous paragraph has ended.
To preserve readability when composing HTML files, separate paragraphs with blank lines. As mentioned above, browsers will ignore blank spaces inserted into source code.
Paragraph Alignment
Paragraph alignment can be manipulated by including either the RIGHT, LEFT, or CENTER (note the Americanized spelling) attributes within the <P> tag as shown below:
HTML Code
<P ALIGN=left> This paragraph is left aligned. </P>
<P ALIGN=CENTER> This is a centred paragraph. </P>
<P ALIGN=RIGHT> This paragraph is right aligned. </P>
Browser Display
This paragraph is left aligned.
This is a cantered paragraph.
This paragraph is right aligned.
Forced Line Breaks
The line break tag <BR> can be used to control how browsers render text. When an HTML document is viewed the text normally does a word-wrap at the end of a line. If a text break is desired before the end of a line, use the <BR> tag to force a line break without any extra space between lines. This element has no closing tag.
HTML Code
CN Tower<BR>
301 Front Street West<BR>
Penthouse<BR>
Toronto, Ontario M5V 2T6<BR>
Canada<BR>
Browser Display
CN Tower
301 Front Street West
Penthouse
Toronto, Ontario M5V 2T6
Canada
Using the <P> tag instead of the <BR> tag for short lines of text, such as the above example, would have resulted in unwanted additional white space.
Try it out!
Open notepad and type the following text below, then save as a .html file, open it up with Google chrome, Firefox, or internet explorer, any browser and you should see a webpage.
Try typing this:
<HTML>
<HEAD>
<TITLE>HTML</TITLE>
</HEAD>
<BODY BGCOLOR="#800080" TEXT="#FFFFFF">
Learning HTML is <B>so</B> much fun!
<P ALIGN=centre>
And it is really <I>easy</I> once you get the hang of it.
</P>
<HR SIZE=3>
</BODY>
</HTML>