Basic html Tutorial

HTML Basics - Using Attributes


Giving a Tag More Character
The control that you have using a simple tag like <p> is somewhat limited. Yes, it can start a new paragraph and move the text down on the page but that's not a really big thrill after you have done it a time or two. There is an easy way to expand the characteristics that a tag has by using something called an attribute.
An attribute is a named characteristic of a tag. It is placed inside the "<" and ">" brackets of the tag. The attribute has a name and may have an associated value. For example, to increase the capability of the <p> tag we can use an attribute named align. This will control the alignment of the text on the web page. The attribute align is used something like:

<p align="center">

or

<p align="left">

or

<p align="right">

In this example, the attribute's name is align and its associated values are center, left, or right.
The effect of using the attribute can be seen in these examples:
If we use something like:

<p align="center">
Put me in the center.

Then the resulting text will look like:

Put me in the center.
If we use something like:

<p align="right">
Put me on the right.

Then the resulting text will look like:

Put me on the right.
If we use something like:

<p align="left">
Leave me on the left.

Then the resulting text will look like:

Leave me on the left.
You may have noticed that the results of using the tag <p align="left"> looked exactly like using a plain <p> tag. That is because the align="left" attribute of the <p> tag is the default value, or the value that will be used if no align attribute is specified.
These days it's very common to see the <div> tag used instead of the <p> tag. Here's an example:
<div align="center">All centered text would go here followed by a closing </div> tag.
Grab the Code
Review
We have examined the use of attributes to expand the capabilities of our tags. Using the align attribute of the <p> tag, we can now place text on the left, right or in the center of the page.
In the next section, we will look at using some attributes in the <body> tag to control the color of our page and the text.
Back Next
[Back] [Table of Contents] [Next]
Copyright © 2007 John H. Bolgiano, Jr. & Roberta Bush - All rights reserved
Modified with permission for educational use by Roberta Bush