Inserting Text into an HTML Document


Introduction | Text | Images | Links | Colors | Tables | Resources

Paragraphs

Text in HTML document are typically entered between the paragraph tags: <P> and </P>.

Paragraph tag <P>
End tag </P> (optional)
Attributes ALIGN (left, right, center)
Example <P ALIGN=LEFT>
left-justified paragraph
</P>

An HTML paragraph contains only one space between letters even if your typed code contains more spaces. Furthermore, line breaks typed in the code appear as a space. To introduce a line break into an HTML paragraph, use <BR> tag. To add spaces between characters, use "&nbsp;". Below are some examples:

HTML code What the browser displays
<P>
three   spaces
</P>
three spaces
<P>
three&nbsp;&nbsp;&nbsp;spaces
</P>
three   spaces
<P>
two

lines
</P>
two lines
<P>
two<BR><BR>lines
</P>
two


lines

Special Characters

To insert symbols into an HTML code, you need to know their name or number code. Below are several commonly used symbols; for a complete listing go to Webmonkey.
Code Description
&nbsp; blank space
&lt; and &gt; brackets <   >
&copy; copyright symbol ©
&#176; degrees symbol °
&#178; squared ²

Horizontal lines can be drawn in a document using <HR> tag. Attributes are SIZE=# to set the line width in pixels, and WIDTH=# to set the span of the line across the page in pixels or percent. For example, <HR SIZE=5 WIDTH=50%> looks like:


Formatting Text

Any text in the HTML file can be formatted using tags.
Tag Pair Description
<B> </B> Bold
<U> </U> Underline
<I> </I> Italics

These tags can be used in combination. Furthermore, font size can be varied using <FONT SIZE=#> and </FONT> tags. Font size can be specified by relative scale (+2, +1, 0, -1, -2, ...) or by absolute sizes.

Exercise 2

  1. In the BODY of your index.html file, create one LEFT-JUSTIFIED paragraph with your name.
  2. Create a RIGHT-JUSTIFIED paragraph with your favorite food.
  3. Create a CENTER-JUSTIFIED paragraph with your birthdate.
  4. Underline your birthdate.
  5. Insert a horizontal line between the three paragraphs, of varying size and width.
  6. Save the file under the same name.

Introduction | Text | Images | Links | Colors | Tables | Resources
© June 2001 | Thermal Analysis of Materials Processing Laboratory
Tufts University Medford, MA 02155 | Contact: Haruna Tada