maxp
maxp

Reputation: 25171

Should I use the <p /> tag in markup?

I have always used either a <br /> or a <div/> tag when something more advanced was necessary.

Is use of the <p/> tag still encouraged?

Upvotes: 18

Views: 31954

Answers (10)

Robert Koritnik
Robert Koritnik

Reputation: 105081

Paragraph is a paragraph, and break is a break.

A <p> is like a regular Return in Microsoft Office Word.
A <br> is like a soft return, Shift + Return in Office Word.

The first one sets all paragraph settings/styles, and the second one barely breaks a line of text.

Yes, <p> elements are encouraged and won't get deprecated any time soon.

Upvotes: 10

user136698
user136698

Reputation:

From the HTML 4.01 Specification:

We discourage authors from using empty P elements. User agents should ignore empty P elements.

While they are syntactically correct, empty p elements serve no real purpose and should be avoided.

Upvotes: 4

Christian Hayter
Christian Hayter

Reputation: 31071

Modern HTML semantics are:

  • Use <p></p> to contain a paragraph of text in a document.
  • Use <br /> to indicate a line break inside a paragraph (i.e. a new line without the paragraph block margins or padding).
  • Use <div></div> to contain a piece of application UI that happens to have block layout.

Don't use <div /> or <p /> on their own. Those tags are meant to contain content. They appear to work as paragraph breaks only because when the browser sees them, and it "helpfully" closes the current block tag before opening the empty one.

Upvotes: 42

Martin Liversage
Martin Liversage

Reputation: 106936

The HTML DTD does not prohibit you from using an empty <p> (a <p> element may contain PCDATA including the empty string), but it doesn't make much sense to have an empty paragraph.

Upvotes: 3

Bhaskar
Bhaskar

Reputation: 10691

For any practical purpose, you don’t need to add the </p> into your markup. But if there is a string XHTML adheration requirement, then you would probably need to close all your markup tags, including <p>. Some XHTML analyzer would report this as an error.

Upvotes: 0

Zack Marrapese
Zack Marrapese

Reputation: 12091

A <p> signifies a paragraph. It should be used only to wrap a paragraph of text.

It is more appropriate to use the <p> tag for this as opposed to <div>, because this is semantically correct and expected for things such as screen readers, etc.

Upvotes: 7

Tyler Carter
Tyler Carter

Reputation: 61597

A <p> tag wraps around something, unlike an <input/> tag, which is a singular item. Therefore, there isn't a reason to use a <p/> tag..


I've been told that im using <br /> when i should use <p /> instead. – maxp 49 secs ago

If you need to use <p> tags, I suggest wrapping the entire paragraph inside a <p> tag, which will give you a line break at the end of a paragraph. But I don't suggest just substituting something like <p/> for <br/>

<p> tags are for paragraphs and signifying the end of a paragraph. <br/> tags are for line breaks. If you need a new line then use a <br/> tag. If you need a new paragraph, then use a <p> tag.

Upvotes: 10

Greg
Greg

Reputation: 321864

Using <p /> has never been encouraged:

From XHTML HTML Compatibility Guidelines

C.3. Element Minimization and Empty Element Content

Given an empty instance of an element whose content model is not EMPTY (for example, an empty title or paragraph) do not use the minimized form (e.g. use <p> </p> and not <p />).

Upvotes: 6

Philippe
Philippe

Reputation: 1823

The <p> tag defines a paragraph. There's no reason for an empty paragraph.

Upvotes: 2

Marius
Marius

Reputation: 59009

Use it for what? All tags have their own little purpose in life, but no tag should be used for everything. Find out what you are trying to make, and then decide on what tag fits that idea best:

If it is a paragraph of text, or at least a few lines, then wrap it in <p></p>

If you need a line break between two lines of text, then use <br />

If you need to wrap many other elements in one element, then use the <div></div> tags.

Upvotes: 2

Related Questions