🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
REFERENCEhtml

html Documentation

LOADING ENGINE...

<p>

AI & DATA SCIENCE // p-tag

The <p> element represents a paragraph of text — the most common way to group and separate blocks of prose in HTML.

Syntax

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

Deep Dive Course

**`<p>`** is a block-level element: browsers render it on its own line, with a small default top/bottom margin separating it from neighboring elements. Historically, `<p>` doesn't strictly require a closing tag — browsers automatically close an open `<p>` when they hit another block-level element — but explicit closing tags are still best practice for clean, predictable markup and for tools that parse your HTML.

1Understanding <p>

`<p>` is a block-level element: browsers render it on its own line, with a small default top/bottom margin separating it from neighboring elements. Historically, <p> doesn't strictly require a closing tag — browsers automatically close an open <p> when they hit another block-level element — but explicit closing tags are still best practice for clean, predictable markup and for tools that parse your HTML.

💡

Never nest a <p> inside another <p>, or put block-level elements like <div> or <table> inside one — the browser's error-recovery will silently close the paragraph early, often breaking your intended layout.

editor.html
<p>HTML paragraphs are block-level elements.</p>
<p>Each one starts on a new line automatically.</p>
localhost:3000

2Practical Example

Here is a real-world application of <p> showing how it is used in production HTML.

editor.html
<!-- Browsers auto-close an open <p> before a new block element -->
<p>Text before
<div>A div, which implicitly closes the paragraph above</div>
localhost:3000

3Best Practices

Follow these guidelines when working with <p>:

1. Use <p> only for actual prose/text content, not for layout spacing

2. Don't nest block-level elements (<div>, <ul>, <table>) inside a <p>

3. Use CSS margin/padding for spacing, not empty <p>&nbsp;</p> tags

⚠️

Tip: Never nest a <p> inside another <p>, or put block-level elements like <div> or <table> inside one — the browser's error-recovery will silently close the paragraph early, often breaking your intended layout.

editor.html
<p>HTML paragraphs are block-level elements.</p>
<p>Each one starts on a new line automatically.</p>
localhost:3000

Examples

Example 01Basic Usage
<p>HTML paragraphs are block-level elements.</p>
<p>Each one starts on a new line automatically.</p>
Example 02Advanced Example
<!-- Browsers auto-close an open <p> before a new block element -->
<p>Text before
<div>A div, which implicitly closes the paragraph above</div>

Best Practices

  • Use

    only for actual prose/text content, not for layout spacing

  • Don't nest block-level elements (
    ,
      , ) inside a

    • Use CSS margin/padding for spacing, not empty

       

      tags
    • Interview Question

      Is the closing </p> tag required in HTML?

      Hint: Think about the HTML5 parsing spec's 'optional tags' rules.

      Technically no — the HTML5 spec allows the closing </p> to be omitted because the parser automatically closes a <p> when it encounters another block-level element or the end of its parent. In practice, you should always write the closing tag: it makes the markup unambiguous, works correctly with strict parsers (like XML/JSX-based tooling), and avoids relying on browser error-recovery behavior.

      Exercises

      EasyPractice using <p> in a real scenario.
      View Solution
      <p>HTML paragraphs are block-level elements.</p>
      <p>Each one starts on a new line automatically.</p>

      Frequently Asked Questions

      Is the closing </p> tag required in HTML?

      Technically no — the HTML5 spec allows the closing

      to be omitted because the parser automatically closes a

      when it encounters another block-level element or the end of its parent. In practice, you should always write the closing tag: it makes the markup unambiguous, works correctly with strict parsers (like XML/JSX-based tooling), and avoids relying on browser error-recovery behavior.

      Related Functions

      div-tagspan-tagblockquote-tag