The <p> tag is used in HTML to delimit a paragraph of text. It is one of the most commonly used tags for structuring textual content on a web page.
Structure and syntax of the <p> tag
Basic structure and syntax
The <p> tag is a container tag, which means it requires a closing tag. It is used to enclose text. Here is its basic syntax:
<p>Paragraph content</p>It groups text or other inline elements to form a distinct paragraph.
Usage example
Let's take a practical example:
<p>Here is a clear and concise paragraph of text.</p>In this example, the content is enclosed by the <p> tag, making it distinct and isolated from other elements on the page.
Try it yourself! 😉
Attributes
The <p> tag accepts standard HTML attributes, such as:
class: to apply personalized CSS styles with a class;id: to identify a unique paragraph on the page;style: to apply CSS styles directly to the tag.
Best practices
- Use
<p>to structure your textual content into distinct paragraphs (which improves readability). - Avoid using it for complex layouts; in such cases, prefer tags like
<div>. - For a simple line break within a paragraph, you can use the
<br>tag.
Difference with other similar tags
<br>: The<br>tag allows for a simple line break within text, whereas<p>creates a distinct paragraph.<div>: Unlike<p>, the<div>tag is a generic container. It can group paragraphs, for example, as well as images, but will not add margins automatically unlike a paragraph which will add one above it by default.
Browser compatibility
The <p> tag is supported by all modern browsers.
| Browser | Compatibility |
|---|---|
| Chrome | Yes |
| Firefox | Yes |
| Safari | Yes |
| Edge | Yes |
| Internet Explorer | Yes |