Websites by Mark

The p html tag – Websites by Mark

01305 881027 / 01993 820005

The p html tag

Overview

In simple terms the <p> HTML tag stands for paragraph. When text is put between the opening and closing <p> tag it is displayed as a paragraph. It is for this reason when you view most of the body copy in the source of a webpage you will see it sitting between <p></p>

Basic Usage

<p>Some text in here</p>

Any text between the opening and closing tag will be displayed as a paragraph.

Advance Usage

It is possible to style and add functionality to the <p> tag, this is done by adding an attribute to after the p in the opening <p> tag

Attributes allowed for the <p>tag include :-class, dir, id, lang, style and title.

In most cases class and id are used and its basic usage is shown below

<p id=”header”>Some text</p>

With all attributes there is a space after the initial p then the attribute name, then an equal’s sign and the identifier of the attribute in double quotes.

Both id and class attributes refer to CSS styling of the element and is either stored in the <head> of the webpage on in an external file.

With id this usually refers to a single instance on a page where as class usually refers to a repeating element on a page, it is for this reason for the <p> tag the class attribute is nearly always used over the id attribute.

The attribute style allows you to include css style information for a single <p> tag.

The dir attribute allows for left reading and right reading text, lang allows you to specify a language for the tag and title allows you to include extra information for a tag.

It is possible to attach scripts to tags, as well adding functionality to a webpage, these scripts tend to be written in Javascript and therefore outside the scope of this document

Examples

<p>Some text</p> – basic usage example.

<p id=”header”>Some text</p> – Paragraph which is styled by the id header.

<p class=”headerclass”> Some text </p> – Paragraph which is styled by the class headerclass.

<p id =”header” class=”headerclass”> Some text </p> – Paragraph which is styled by the class headerclass and the id header.

<p style=”color:#F00″>Some text</p> – Paragraph which has a custom colour of red.

<p dir=”rtl”>Some text</p> – Paragraph where the text reads from right to left.

<p lang=”uk”>Some text</p> – Paragraph where the language has been tagged as UK.

<p title=”ptitle”>Some text</p> – Paragraph where the tag has been titled ptitle.

Final Thoughts

Touching on just the surface of the <p> HTML tag it is easy to see how versatile it is. To take full advantage of it an understanding of CSS is an advantage.