# p element

Type: | Text Blocks
Attributes: | orphans • text-align • text-indent • color • font-family • font-feature-settings • font-stretch • font-style • font-variant • font-weight • font • justification-ratio • letter-spacing • outline-color • outline-width • overprint • requote • suppress-ligatures • text-decoration • text-transform • align • background-color • background-image-dpi • background-image-position • background-image • background-pdf • border-color • border-style • border-width • border • clear • corner-radius • display • float • font-size • height • href • left • line-cap • line-height • line-join • margin • onmouseover • overflow • padding • page-break-after • page-break-inside • position • rotate • size • top • vertical-align • visibility • white-space • width • class • colorspace • direction • id • lang
See: | a b blockquote body div h1 h2 h3 h4 i img li pre span table td

The p tag is the basic type of paragraph in the document. All text displayed in the document must be inside a paragraph, either a p or one if it's subtypes (h1 to h4, pre, blockquote) or an "anonymous" p tag, inserted by the XML parser itself.
A paragraph is a rectangle, or block, on the page (in fact it's a special class of DIV. Like other blocks it can have padding, margin and borders specified. As well as inline blocks like span, b, i and so on, since version 1.1, a paragraph can have "block" elements like img and table as children as well.
There are three possible ways to include a block element inside a paragraph.

1. The display attribute of the block may be set to "inline". This will cause the block to appear in the middle of the text. The vertical-align attribute can be used to set it's vertical alignment
2. The float attribute may be set to "left" or "right" to cause the block to "drift" to the left or right of the paragraph, with the text content of the paragraph wrapping around it. The clear attribute may also be set to control exact positioning
3. The element may be left with the default display attribute of "block". This will cause the elements to be placed inside the paragraph using the regular one-block-after-another vertical layout.

Note that despite the last method, if a number of items with display set to "block" are to be displayed then it's recommended that the paragraph is ended and the items displayed as siblings, rather than children, of the p element. This is more efficient in terms of both speed and memory use.
As a convenience, anonymous paragraphs are added in certain situations by the XML parser during the parsing process. Specifically, if text or a span element is found inside a body, td or li tag, an paragraph will be created around the text. See the examples below.

This is the "normal" use of a paragraph. Text is explicitly surrounded by a P element.

    <body>
      <p>This is the normal use of a paragraph</p>
    </body>

An anonymous paragraph would be created in this situation, as text is directly inside the BODY element. Internally the XML is translated into the same structure as the previous example.

    <body>
      This is an anonymous paragraph
    </body>

When embedding blocks, this is how to use the first option listed above.

    <body>
      <p>
        This text is broken in the middle
        <img display="inline" src="image.gif"/>
        by an image
      </p>
    </p>
    </body>

When embedding blocks, this is how to use the second option listed above.

    <body>
      <p>
        <img display="inline" float="left" src="image.gif"/>
        This text wraps around an image, which is positioned at the left edge of
        the paragraph block
      </p>
    </p>

When embedding blocks, this is how to use the third option listed above.

    <body>
      <p>
        This text is displayed above the image
        <img display="block" src="image.gif"/>
        and this text is displayed below the image.
      </p>
    </p>