HTML Paragraphs

HTML Paragraphs

Paragraphs are defined with the <p> tag.

Example:

<p>This is a paragraph.</p>
<p>This is another paragraph.</p>

Note: Browsers automatically add space before and after paragraphs. The <p> tag is a block-level element.

Don't Forget the Closing Tag

Even if you forget to use a closing tag, most browsers will still display the HTML correctly:

Example:

<p>This is a paragraph
<p>This is another paragraph

The above example will render correctly in most browsers, but do not rely on this practice. Forgetting to use closing tags can lead to unexpected results and errors.

Note: Future versions of HTML will not allow the omission of closing tags.

HTML Line Breaks

If you want to insert a line break without creating a new paragraph, use the <br> tag:

Example:

<p>This<br>paragraph<br>demonstrates<br>line breaks.</p>
The <br /> element is an empty HTML element. It has no end tag because it doesn't make sense to have one.

HTML Output - Important Reminders

We cannot determine the exact display effect of HTML. Screen sizes and window adjustments can cause different results.

In HTML, you cannot change the output effect by adding extra spaces or line breaks in the HTML code.

When displaying a page, browsers remove any extra spaces and blank lines from the source code. All consecutive spaces or blank lines are counted as a single space. Note that all consecutive blank lines (line breaks) in the HTML code are also displayed as a single space.

(This example demonstrates some HTML formatting issues)

Examples

HTML Paragraphs:

How HTML paragraphs are displayed in a browser.

<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>

Line Breaks:

Using line breaks in an HTML document.

<p>This<br>paragraph<br>demonstrates the effect of line breaks.</p>

Formatting a Tang Poem in HTML Code:

When displaying HTML, browsers omit excess white space characters (spaces or carriage returns).

<h1>Spring Morning</h1>
<p>
    I wake up in the spring without realizing dawn has come,<br>
    Everywhere I hear birds singing.<br>
    The sound of wind and rain came last night,<br>
    And who knows how many flowers have fallen.
</p>
<p>Note that the browser ignores the formatting in the source code (omitting extra spaces and line breaks).</p>

More Examples

More Paragraphs:

The default behavior of paragraphs.

<p>
This paragraph<br>
contains multiple lines<br>
in the source code,<br>
but the browser<br>
ignores them.
</p>
<p>
This paragraph<br>
contains multiple lines<br>
in the source code,<br>
but the browser<br>
ignores them.
</p>
<p>The number of lines in a paragraph depends on the size of the browser window. Adjusting the size of the browser window will change the number of lines in the paragraph.</p>

HTML Tag Reference Manual

Our site's tag reference manual provides more information about HTML elements and their attributes.

Tag Description
<p> Defines a paragraph
<br> Inserts a single line break