Search this site...

Creating Paragraphs in XHTML

The <p> tag is one of the most commonly used tags. The <p> tag contains paragraph text. Creating a paragraph in XHTML is very similar to what you do in HTML but with one noticeable exception: in HTML, your paragraphs will render correctly even if you fail to close the paragraphs tag this is not the case in XHTML. In XHTML, every opened tag must be properly closed.

Recall opening tag is the name of the tag surrounded by two angled brackets such as <p>, and closing tag simply has in addition a forward slash (/) between the less than sign and the name of the tag (i.e., </p>). Opening tag indicates start of an instruction and closing tag indicates end of the instruction. So opening tag, <p>, indicates start of a paragraph and the closing tag, </p> marks the end of a paragraph.

The following shows an example of creating a paragraph in XHTML:

<p>To create a paragraph in XHTML, have opening and closing tags around your paragraph text as it is done in this example. This is the text for our paragraph. Now, ending the paragraph.</p>

The following shows the output of the above scripting code:

Browser output of a paragraph
Browser output of a paragraph

In the following example, we create multiple paragraphs using separate paragraphs tags:

<p>This is our first paragraph. Creating a paragraph in XHTML is easy. Simply place opening and closing tags around the text you want to designate as a paragraph. And, the browser will render it as a paragraph.</p>

<p>This strats our second paragraph. As you may have already realized, this paragraph too uses the same markup tag; namely, the <p> tag. Each new paragraph opening tag (<p>) starts the paragraph text on new line in the browser output. The browser is responsible for separating each paragraph from other paragraphs with a blank line. So you don't have to manually insert blank lines (using the <br> tag). With style sheets, you can actually customize the precise blank space that you want to use for separating paragraphs. See the output below.</p>

The following shows how a browser shows the two paragraphs created above:

Showing browser output of multiple paragraphs
Showing browser output of multiple paragraphs