HTML Paragraphs
π§Ύ What Is a Paragraph in HTML?
In HTML, the <p> tag is used to define a paragraph of text. It is a block-level element that automatically adds spacing above and below its content.
>>βParagraphs bring structure and readability to your content.β π
π Syntax
Basic Paragraph Tag
<p>This is a paragraph of text.</p>You should always use the <p> tag when writing paragraphs to ensure semantic meaning and accessibility.
π Behavior
- π§± It is a block-level element and takes full width.
- π Adds spacing by default (via browser styles).
- β Does not allow other block-level elements inside.
π§ͺ Examples
Multiple Paragraphs
<p>This is the first paragraph.</p>
<p>This is the second paragraph, below the first one.</p>
Note
β οΈ Avoid using multiple line breaks (<br />) to create paragraphs. Always use <p> for semantic clarity.
π§ Using Line Breaks
If you want a line break within a paragraph, use the <br /> tag:
Line Break in Paragraph
<p>
This is line one.<br />
This is line two.
</p>Note
π‘ Use <br /> sparingly β only when the line break is intentional and not suitable for a new paragraph.
π Paragraph Tag Attributes
| Attribute | Description |
|---|---|
| id | Unique identifier for the paragraph |
| class | CSS class name to style the paragraph |
| title | Tooltip text shown on hover |
| style | Inline CSS styling |
π¨ Styling Paragraphs
You can style paragraphs using CSS. Hereβs an example:
Styled Paragraph
<p style="color: darkblue; font-size: 18px;">
This is a styled paragraph.
</p>Note
β
Prefer using class with external CSS for larger projects instead of inline styles.
π Learn More
>>βHTML paragraphs are not just about text β theyβre about giving your ideas space to breathe.β π¬οΈ