The paragraph <p> element of HTML is used to insert a paragraph of text in the HTML Document. Though the paragraph element inserts a paragraph in the document, the first line of the paragraph does not get automatically indented as in normal paragraphs that we find in text books. To indent the paragraph we have to use either Style Sheets or we can use the special HTML symbols fo the tab etc.. The paragraph element is a closed tag and its contents make the paragraph.
Syntax:
<p property=”value” property=”value” …>
Paragraph Contents
</p>
Valid Properties:
The properties supported by the <p> element are as -
1. align This property sets the horizontal alignment of the contents of the paragraph. The possible values are any one from – center, left, right and justify. Note that the align property is supported only in the Transitional Version of the HTML. In Strict versions and XHTML, this is to be implemented using the Style Sheets.
Other properties for the <p> element include the following common properties – class, dir, id, lang, style, title.
Refer to Common Properties page for details of these properties.
Example:
<p align=”center”> This is a sample paragraph text to display the fact that the paragraph content is not indented via HTML. One has to use Style Sheets and / or HTML special Characters to get the first line of text indented as in any normal paragraph. Also note that when a paragraph element is used, it automatically inserts a blankline after the content of the paragraph. The paragraph element is a closed tag and as such you have to use the normal closing method for the paragraph element.</p>
Notes:
1. As <p> is a block level element, browsers typically insert a blank line. But this can be changed in case you are using Style Sheets.
2. Under Strict HTML and XHTML, there is no support for the align property and this is implemented using Style Sheets.
3. The indention of the first line of the paragraph is also handled using Style Sheets.
4. Though </p> is optional under the HTML, it is always advisable to end the paragraph with the </p> as this indicates the logical end of a paragraph. Also, XHTML requires that the <p> element must have a matching </p> to close off the <p> element.
5. Just as multiple consecutive spaces and other whitespaces are rendered as a single space or white space character, consecutive empty paragraph elements are rendered as a single paragraph on mots browsers. As such, avoid using paragraph element to insert blank lines in the document. In case you need blank lines, use the <br /> element.
6. HTML 3.2 does not support justify value for the align property.
7. HTML 2.0 does not support any property for the <p> element.
Filed under: Block Level Elements Tagged: | Education, HTML / XHTML, Learn HTML, Learn XHTML, Training, Web Site Development