Sams Teach Yourself HTML 4 in 24 Hours
- Table of Contents
- Copyright
- About the Author
- Acknowledgments
- Tell Us What You Think!
- Put Your HTML Page Online Today
- I. Your First Web Page
- Hour 1. Understanding HTML and XML
- Hour 2. Create a Web Page Right Now
- Hour 3. Linking to Other Web Pages
- Hour 4. Publishing Your HTML Pages
- II. Web Page Text
- Hour 5. Text Alignment and Lists
- Hour 6. Text Formatting and Font Control
- Hour 7. Email Links and Links Within a Page
- Hour 8. Creating HTML Forms
- III. Web Page Graphics
- Hour 9. Creating Your Own Web Page Graphics
- Hour 10. Putting Graphics on a Web Page
- Hour 11. Custom Backgrounds and Colors
- Hour 12. Creating Animated Graphics
- IV. Web Page Design
- Hour 13. Page Design and Layout
- Hour 14. Graphical Links and Imagemaps
- Hour 15. Advanced Layout with Tables
- Hour 16. Using Style Sheets
- V. Dynamic Web Pages
- Hour 17. Embedding Multimedia in Web Pages
- Hour 18. Interactive Pages with Applets and ActiveX
- Hour 19. Web Page Scripting for Non-Programmers
- Hour 20. Setting Pages in Motion with Dynamic HTML
- VI. Building a Web Site
- Hour 21. Multipage Layout with Frames
- Hour 22. Organizing and Managing a Web Site
- Hour 23. Helping People Find Your Web Pages
- Hour 24. Planning for the Future of HTML
- VII. Appendixes
- A. Readers' Most Frequently Asked Questions
- B. HTML Learning Resources on the Internet
- C. Complete HTML 4 Quick Reference
- D. HTML Character Entities
Text Alignment
Some HTML tags allow you to specify a variety of options, or attributes, along with the basic tag itself. For example, when you begin a paragraph with the <p> tag you can specify whether the text in that paragraph should be aligned to the left margin, right margin, or center of the page.
To align a paragraph to the right margin, you can put align="right" inside the <p> tag at the beginning of the paragraph. To center a paragraph, use <p align="center">. Similarly, the tag to align a paragraph to the left is <p align="left">. (This is seldom used because paragraphs are always aligned to the left when you use plain old <p>.)
The word align is called an attribute of the <p> tag. You can use the align attribute with just about any HTML tag that contains text, including <h1>, <h2>, the other heading tags, and some tags you will meet later. There are many other attributes besides align. You will find out how to use them as you learn more HTML tags.
Attributes are special code words used inside an HTML tag to control exactly what the tag does.
According to the official HTML 4 standard, it doesn't matter whether tags and attributes are in uppercase or lowercase letters. However, the newer XHTML standard will require tags and attributes to be lowercase, so it's a very good idea to make all your HTML lowercase now for future compatibility. The new standard will also require quotation marks around attribute values.
For example, the following is technically okay now:
<P ALIGN=CENTER>
If you want to stay compatible with upcoming standards and software, you should always use the following instead:
<p align="center">
When you want to set the alignment of more than one paragraph or heading at a time, you can use the align attribute with the <div>, or division, tag. By itself, <div> and its corresponding closing </div> tag actually don't do anything at all—which would seem to make it a peculiarly useless tag!
Yet if you include an align attribute, <div> becomes quite useful indeed. Everything you put between <div align="center"> and </div>, for example, is centered. This may include lines of text, paragraphs, headings, images, and all the other things you'll learn how to put on Web pages in upcoming chapters. Likewise, <div align="right"> will right-align everything down to the next </div> tag.
Figure 5.1 demonstrates the align attribute with both the <p> and <div> tags. The results are shown in Figure 5.2. You'll learn many more advanced uses of the <div> tag in Hour 16, "Using Style Sheets," and Hour 20, "Setting Pages in Motion with Dynamic HTML."
Figure 5.1 The align attribute allows you to left-justify, right-justify, or center text.
Figure 5.2 The alignment settings in Figure 5.1, as they appear in a Web browser.
The Three Types of HTML Lists | Next Section

Account Sign In
View your cart