XHTML - <p (attr)="..."> Paragraph Tag with Attributes
Definition
See <p> </p> Paragraph for basic information about this tag.
Attributes
align (deprecated)
This attribute is deprecated. Instead use a “style” statement. See example below.
The following examples use the align attribute.
<p align="left">This is a paragraph</p>
<p align="right">This is a paragraph</p>
<p align="center">This is a paragraph</p>
<p align="justify">This is a paragraph</p>
The code examples above are correctly shown using the "style" attribute here.
<p style="text-align:left">This is a paragraph</p>
<p style="text-align:right">This is a paragraph</p>
<p style="text-align:center">This is a paragraph</p>
<p style="text-align:justify">This is a paragraph</p>
Output
This is a paragraph
This is a paragraph
This is a paragraph
This is a paragraph
A Little Deeper
I try to avoid any inline styling if I can avoid it. A much better way to handle this is to assign a class to each paragraph and style that class in the <head> or in a separate CSS file.
You'll understand why this is done when you have several styling characteristics added to a paragraph (alignment, margin, padding, font size, etc.) and you've added it inline for the sixth time on a page.
id (optional)
id is a unique identifier attached to the paragraph. Each id attribute in an XHTML document, no matter what element it is a part of, must be unique to function properly. The id attribute is used by CSS and javascript to modify the content or presentation of the paragraph.
The paragraph in the following example has the id "para1".
<p id="para1">This is the text in the first paragraph</p>
class (optional)
class is an identifier attached to the paragraph. class is usually not a unique attribute, but is actually attached to several different elements. The class attribute is used by CSS and javascript to modify the content or presentation of the paragraph.
The paragraph in the following example has the class "para2".
<p class="para2">This is the text in the first paragraph</p>
The paragraph in the following example has two classes "para3" and "para4".
<p class="para3 para4">This is the text in the first paragraph</p>
A paragraph may have both an id attribute and one or more class attributes. The paragraph in the following example has an id "para5" and two classes "para6" and "para7".
<p id="para5" class="para6 para7">This is the text in the first paragraph</p>
title (optional)
The title attribute determines the text that will appear in the small pop-up box when the cursor is placed over the paragraph. This attribute is not often used with a paragraph because users are used to seeing it used with links of some sort, and therefore the user might think that the paragraph is a link when they see the small pop-up text.
Example
<p title="You should be able to see this text when the cursor is over the paragraph">Place the cursor over this paragraph to see the text in the "title" attribute.</p>
Output
Place the cursor over this paragraph to see the text in the "title" attribute.
style (optional)
The style attribute is used to apply inline CSS styling to an element. An example of inline styling using the style attribute is shown above under the align attribute. There are many possible property and value combinations that can be set with inline CSS styling. Please see the CSS section of this website for a list of the possible combinations.
dir (optional)
The dir attribute controls the direction of the text in a paragraph. Maybe. Even if text is specified to be run right to left, the browser may not display the text as expected. Text direction may be controlled for an entire document by the specified language or the browser defaults. It is not recommended that users attempt to use this attribute with this element.
Example
<p dir="ltr">The text in this paragraph is displayed from left to right. This is the default direction for English language websites.</p>
<p dir="rtl">The text in this paragraph is displayed from right to left.</p>
Output
The text in this paragraph is displayed from left to right. This is the default direction for English language websites.
The text in this paragraph is displayed from right to left.
lang (optional)
The “lang” attribute is used to specify the language used in the element. If you are curious, there is a great deal of information available from w3.org here.
xml:lang (optional)
This is an attribute specifically for XML documents to specify the language of the element containing the attribute. This is a fairly rare tag. For more information check out the w3.org recommendation here.
Return to XHTML Tags with Attributes List
Go to XHTML Tags List
BestWebTutorials.com is a free service of CrystalClearWeb.net. You can help us keep providing free tutorials and information by:
- Link to us
- Tell a friend
- Correct any you might find
- Make for improvement
- Make a donation
BestWebTutorials.com attempts to post accurate information on this site, but we cannot guarantee that errors do not sometimes occur. The use of code examples from this site in any other site is at the user's own risk. We cannot guarantee that our code might not be in conflict with code written by others, or that our code is fit for other uses.
For further information please review our Terms of Use and Privacy Policy.
Copyright 2005-2008 CrystalClearWeb.net. All rights reserved.

