views:

596

answers:

11

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

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

+10  A: 

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.

Chacha102
In my opinion this does not answer the question.
tharkun
"Is use of the `<p/>` tag encouraged", I'm saying it shouldn't be used, which then should filter down to 'not encouraged'.
Chacha102
Well, know it answers the question.
tharkun
That is a bad habit of mine. I tend to post really fast and then edit a lot in.
Chacha102
Chacha102: Stackoverflow seems to encourage the *answer real quick, then edit in details* workflow, especially for questions which are going to get a lot of answers. Hard to be the "fastest gun in the west" when you're typing a detailed answer. This is, I think, rather unfortunate.
derobert
Not so. As a question asker, who doesn't want a few immediate answers? The speed of getting answers is worth the lag between answer and detail. If at any point in time an answer is wrong, the mechanism of downvoting is a valid effect to deal with that. So answers that are right but aren't fully detailed work fine, answers that are wrong then right and fully detailed get downvoted then upvoted when they become correct, and answers that are posted all at once get voted on appropriately. The system works.
Tchalvak
+6  A: 

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.

Zack
+1  A: 

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.

Marius
+2  A: 

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

Philippe
A: 

For any practical purpose you dont need to add the </p> into your markup. But if there is 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.

Bhaskar
You need to use tick marks to escape HTML tags in posts. I edited them in for you.
Chacha102
+3  A: 

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.

Martin Liversage
+6  A: 

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 />).

Greg
+14  A: 

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 its own, those tags are meant to contain content. They appear to work as paragraph breaks only because when the browser sees them, it "helpfully" closes the current block tag before opening the empty one.

Christian Hayter
+5  A: 

Interestingly, Counting paragraph tags states that a random sample of 833,866 HTML documents found that 50.1% of the documents sampled contain only <p>...</p>, 4.41% contain only ...<p>..., and a mere 0.21% contain only ...<p/>....

lance
+4  A: 

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.

Altherac
+1  A: 

Paragraph is a paragraph, break is a break.

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

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

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

Robert Koritnik