<p> Organizing Text into ParagraphsThe <p> element is a very popular one when dealing with text in Web pages; it allows you to break text up into paragraphs. Paragraphs are block elements that you can format as you like in stylesheets or with style attributes, including indenting the first line and so forth. If you're coming to XHTML from HTML, one issue to flag is that every <p> tag needs a corresponding </p> tag, which is easy to forget because HTML doesn't require that. In addition, note that paragraphs are block elements, which in XHTML means that you cannot display other block elements, such as headings, in them. The <p> element is supported in XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, and XHTML 1.1. Here are this element's attributes:
This element supports these XHTML events: onclick , ondblclick , onmousedown , onmouseup , onmouseover , onmousemove , onmouseout , onkeypress , onkeydown , and onkeyup . You use the <p> element to organize your text into paragraphs. Paragraphs are rudimentary formatting structures that separate text into easily handled block elements. The browser adds a little vertical space on top to separate them from other elements. The browser formats the text in a paragraph to fit the current page width. Here's the XHTML example using the <p> tag we saw in the previous topic: <?xml version="1.0"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title> Using the <br> and <p> Elements </title> </head> <body> <center> <h1> Using the <br> and <p> Elements </h1> </center> This is a line of text. <br /> Using a line break skips to the next line. <p style="font-weight: bold"> This is a line of bold text in a paragraph. <br /> Here's a new line of text in the same paragraph. </p> </body> </html> This example points out the difference between <br> and <p> . The <br> element is empty and just makes the flow of text skip to the next line. The <p> element, on the other hand, is a block element that encloses content. You can apply styles to the content in a <p> element, and those styles are applied to all text in the paragraph, even if broken up with line breaks. You can see this in Figure 16-9, where the bold style of text applies to both lines in the paragraph. |