Home > Articles

📄 Contents

  1. Sprucing Up Your Text
  2. A Few Formatting Features You'll Use All the Time
  3. Textras: Fancier Text Formatting
  • Print
  • + Share This
This chapter is from the book

A Few Formatting Features You'll Use All the Time

This section takes you through five more formatting tags that should stand you in good stead throughout your career as a web engineer. You use these tags for adding headings, aligning paragraphs, displaying "preformatted" text, inserting line breaks, and displaying horizontal lines. The next few sections give you the details.

Sectioning Your Page with Headings

Many web designers divide their page contents into several sections, like chapters in a book. To help separate these sections and thus make life easier for the reader, you can use headings. Ideally, headings act as minititles that convey some idea of what each section is all about. To make these titles stand out, HTML has a series of heading tags that display text in larger, bold fonts. There are six heading tags in all, ranging from <H1>, which uses the largest font, down to <H6>, which uses the smallest font.

What's with all the different headings? Well, the idea is that you use them to outline your document. As an example, consider the headings I've used in this chapter and see how I'd format them in HTML.

The overall heading, of course, is the chapter title, so I'd display it using, say, the <H1> tag. The first main section is the one titled "Sprucing Up Your Text," so I'd give its title an <H2> heading. That section contains three subsections, "Some Basic Text Formatting Styles," "Combining Text Formats," and "Accessorizing: Displaying Special Characters." I'd give each of these titles the <H3> heading. Then I come to the section called "A Few Formatting Features You'll Use All the Time." This is another main section of the chapter, so I'd go back to the <H2> tag for its title, and so on.

Webmaster Wisdom

Notice that I force the browser to display a less-than sign (<) by using the character code &lt;, and to display a greater-than sign (>) by using the code &gt;.

The following HTML document (look for headings.htm on the website) shows how I'd format all the section titles for this chapter, and Figure 3.2 shows how they appear in Internet Explorer on the Mac. (Notice that I don't need to use a <P> tag to display headings on separate lines; that's handled automatically by the heading tags.)

<TITLE>Some Example Headings</TITLE>
<H1>From Buck-Naked to Beautiful: Dressing Up Your Page</H1>
<H2>Sprucing Up Your Text</H2>
<H3>Some Basic Text Formatting Styles</H3>
<H3>Combining Text Formats</H3>
<H3>Accessorizing: Displaying Special Characters</H3>
<H2>A Few Formatting Features You'll Use All the Time</H2>
<H3>Sectioning Your Page With Headings</H3>
<H3>Aligning Paragraphs</H3>
<H3>Handling Preformatted Text</H3>
<H3>Them's the Breaks: Using &lt;BR&gt; for Line Breaks</H3>
<H3>Inserting Horizontal Lines</H3>
<H2>Textras: Fancier Text Formatting</H2>
<H3>The &lt;FONT&gt; Tag I: Changing the Size of Text</H3>
<H3>The &lt;BASEFONT&gt; Tag</H3>
<H3>The &lt;FONT&gt; Tag II: Changing the Typeface</H3>
<H3>Changing the Color of Your Page Text</H3>
<H3>The &lt;FONT&gt; Tag III: Changing the Color</H3>
<H3>The Dreaded &lt;BLINK&gt; Tag</H3>

Figure 3.2 Examples of HTML's heading tags.

Aligning Paragraphs

Centering text and graphics is a time-honored way to give reports and brochures a professional look and feel. To provide the same advantage to your web pages, the <CENTER> tag gives you centering capabilities for your page headings, paragraphs, lists, and even graphics. Here's how <CENTER> works:

[Headings, text, and graphics that you want centered go here.]

The <CENTER> tag is a nice, simple way to shift things to the middle of a page. How-ever, you can also use the <P> tag and the heading tags by shoehorning some extra text inside the tag. This extra text is called an attribute and it tells the browser to modify how it normally displays the tag.

For example, to center a paragraph, you use the following variation on the <P> tag theme:


When the browser stumbles upon the ALIGN attribute, it knows that it's going to have to modify the behavior of the <P> tag in some way. The exact modification is supplied by the value of the attribute, which is "CENTER" in this case. This orders the browser to display the entire contents of the following paragraph centered in the browser window.

Similarly, you can center, say, an <H1> heading like so:


The advantage to this approach is that you can also use either LEFT or RIGHT with the ALIGN attribute to further adjust your paragraph alignment. The LEFT value aligns the text on the left side of the window (that is, the normal alignment), and the RIGHT attribute aligns the text on the right side of the window.

Page Pitfalls

Always surround attribute values with quotation marks, like so:


And if your page doesn't display properly when you view it in the browser, immediately check to see if you left off either the opening or closing quotation mark.

Handling Preformatted Text

In the previous chapter, I told you that web browsers ignore white space (multiple spaces and tabs) as well as carriage returns. Well, I lied. Sort of. You see, all browsers normally do spit out these elements, but you can talk a browser into swallowing them whole by using the <PRE> tag. The "PRE" part is short for "preformatted," and you normally use this tag to display preformatted text exactly as it's laid out. Here, "preformatted" means text in which you use spaces, tabs, and carriage returns to line things up.

Let's look at an example. The following bit of code is an HTML document (look for pre.htm on the website) in which I set up two chunks of text in a pattern that uses spaces and carriage returns. The first bit of doggerel doesn't make use of the <PRE> tag, but I've surrounded the second poem with <PRE> and </PRE>. Figure 3.3 shows the results. Notice that the lines from the first poem are strung together, but that when the browser encounters <PRE>, it displays the white space and carriage returns faithfully.

<TITLE>The &lt;PRE&gt; Tag</TITLE>
<H3>Without the &lt;PRE&gt; Tag:</H3>
    some ditty,
   specially done,
  to lay it out all
 formatted and pretty.
Unfortunately, that is all
 this junk really means,
   because I admit I
   couldn't scrawl
    poetry for
<H3>With the &lt;PRE&gt; Tag:</H3>
    some ditty,
   specially done,
  to lay it out all
 formatted and pretty.
Unfortunately, that is all
 this junk really means,
   because I admit I
   couldn't scrawl
    poetry for

Webmaster Wisdom

You'll notice one other thing about how the browser displays text that's ensconced within the <PRE> and </PRE> tags: It formats the text in an ugly monospaced font. The only way to get around this is to use something called a "style sheet" to specify the font you want the browser to use with the <PRE> tag. I show you how this works in Part 3, "High HTML Style: Working with Style Sheets."

Figure 3.3 How preformatted text appears in Netscape 6.

Them's the Breaks: Using <BR> for Line Breaks

As you saw in the previous chapter, you use the <P> tag when you need to separate your text into paragraphs. When a browser spies a <P> tag, it starts a new paragraph on a separate line and inserts an extra, blank line after the previous paragraph. However, what if you don't want that extra line? For example, you might want to display a list of items with each item on a separate line and without any space between the items. (Actually, there are better ways to display lists than the method I show you here; see Chapter 4, "The Gist of a List: Adding Lists to Your Page.")

Well, you could use the <PRE> tag, but your text would appear in that ugly, monospaced font. A better solution is to separate your lines with <BR>, the line break tag. A browser starts a new line when it encounters <BR>, but it doesn't toss in an extra blank line. Here's an example (it's the file named breaks.htm on the website):

<TITLE>Line Breaks</TITLE>
<H2>Supply Without the Demand</H2>
<TT>Print-on-demand</TT> is new system that lets bookstores print out a book
whenever a customer asks for one. It's <I>really</I> slick. Recently, I was in
a store called <b>The Book "Seller"</B> and it had a service called <B>Print-
On-Non-Demand</B>&#174; featuring books that <I>very</I> few people would ever
order, much less print out. The titles included the following
The Complete Idiot's Guide to Village Idiocy<BR>
The 10-Minute Guide to Butt-Scanning<BR>
Baby's First Book of Java<BR>
Leashes Unleashed<BR>
Programmer's Guide to Basic Hygiene<BR>
Teach Yourself the Presidency in 4 Years

In the list of books, I added the <BR> tag to the end of each line (except the last one; I don't need it there). As you can see in Figure 3.4, Internet Explorer dutifully displays each line separately, with no space in between.

Figure 3.4 Use the <BR> tag to force a line break in your text.

Inserting Horizontal Lines

If you're particularly eagle-eyed, you might have noticed a horizontal line extending across the browser screen shown in Figure 3.4. What gives? Well, while you weren't looking, I surreptitiously inserted an <HR> tag into the HTML text. <HR>, which stands for "horizontal rule," produces a line across the page, which is a handy way to separate sections of your document.

If you use <HR> by itself, you get a standard line that goes right across the page. How-ever, there are various attributes associated with the <HR> tag that enable you to change the line's size, width, alignment, and more. Table 3.3 shows a rundown.

Table 3.3 Extra Attributes for the <HR> Tag

<HR> Extension

What It Does

<HR WIDTH="x">

Sets the width of the line to x pixels

<HR WIDTH="y%">

Sets the width of the line to y percent of the window

<HR SIZE="n">

Sets the thickness of the line to n pixels (where the default thickness is 1 pixel)


Aligns the line with the left margin


Centers the line


Aligns the line with the right margin


Displays the line as a solid line (instead of appearing etched into the screen)

Note that you can combine two or more of these attributes in a single <HR> tag. For example, if you want a line that's half the width of the window and is centered, then you'd use the following tag:


Webmaster Wisdom

The <HR> tag draws a plain horizontal line. You might notice some web pages have fancier lines that use color and other neat texture effects. Those lines are actually images; I show you how to add images to your page in Chapter 6, "A Picture Is Worth a Thousand Clicks: Working with Images."

  • + Share This
  • 🔖 Save To Your Account

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information

To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.


Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.


If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information

Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.


This site is not directed to children under the age of 13.


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information

If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information

Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents

California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure

Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact

Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice

We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020