HTML Tutorial · Lesson 13

Paragraph Tag

Learn how the <p> tag creates structured paragraphs, how paragraph elements can be styled, and how to use them correctly in an HTML document.

FREE

Paragraph Tag

To create well-structured text in your HTML document, the <p> tag is essential for defining paragraphs. It helps divide written content into clear, readable blocks instead of placing everything into one long piece of text.

<p> Tag: Defining a Paragraph in HTML

The <p> tag is used to format text into distinct paragraphs. Browsers normally place some space between paragraph elements, which provides a clear visual separation between separate pieces of text.

A paragraph element normally has both an opening <p> tag and a closing </p> tag.

Syntax:

<p>
    <!-- Paragraph content -->
</p>

A simple paragraph can be written like this:

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

Multiple Paragraphs

You can use multiple <p> elements to divide a page into separate sections of text. Each paragraph is treated as its own block.

<p>This is the first paragraph.</p>

<p>This is the second paragraph.</p>

<p>This is the third paragraph.</p>

Using separate paragraph elements makes long content easier to read and gives the document a clearer structure.

Attributes and Styling

While the <p> tag is straightforward, you can enhance its functionality using attributes such as class or id for CSS styling. You can also use the style attribute for inline CSS.

Example:

<p class="example" style="color: blue;">
    This is a styled paragraph.
</p>

In this example, the paragraph has a class named example, while the style attribute changes the text color directly on the element.

Paragraphs and Line Breaks

Paragraphs are useful when you want to separate complete thoughts or sections of text. When you only need to move text to a new line without creating a new paragraph, the <br> tag can be used.

<p>
    This is the first line.<br>
    This is the second line.
</p>

Paragraphs for Readable Content

A well-structured webpage usually breaks larger pieces of text into meaningful paragraphs. This makes content easier to scan and gives readers natural visual pauses as they move through the page.

For example, a simple ShadowCraft tutorial section could be structured like this:

<h2>Learning HTML</h2>

<p>
    HTML provides the structure of a webpage.
</p>

<p>
    Once the structure is ready, CSS can be used
    to control its visual presentation.
</p>

When to Use the <p> Tag

  • Use <p> for normal blocks of written content.
  • Use separate paragraphs when a new idea or thought begins.
  • Use class or id when a paragraph needs to be targeted by CSS or JavaScript.
  • Use semantic elements such as <section> or <article> when you need to describe larger page sections.

Best Practices

It is advisable to use the <p> tag for textual content and not for layout control. For layout purposes, consider using semantic HTML elements such as <section> and <article>, together with CSS for spacing and positioning.

Keeping structure and presentation separate makes your HTML easier to maintain and gives your CSS greater control over the appearance of the page.

Video Tutorial

Use the space below for the paragraph-tag video tutorial.

Quick Summary

  • <p> is used to define a paragraph.
  • Each paragraph normally starts as a separate block of content.
  • class, id, and style can be used to style or target a paragraph.
  • Use semantic HTML and CSS rather than paragraphs for page layout.