I have always used either <br />
or a <div/>
tag when something more advanced is necessary.
Is use of the <p/>
tag still encouraged?
I have always used either <br />
or a <div/>
tag when something more advanced is necessary.
Is use of the <p/>
tag still encouraged?
The
<p>
tag defines a paragraph. There's no reason for an empty paragraph.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.The HTML DTD does not prohibit you from using an empty
<p>
(a<p>
element may containPCDATA
including the empty string) , but it doesn't make much sense to have an empty paragraph.Modern HTML semantics are:
<p></p>
to contain a paragraph of text in a document.<br />
to indicate a line break inside a paragraph (i.e. a new line without the paragraph block margins or padding).<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.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 breaks a line of text.
Yes
<p>
elements are encouraged, and won't get deprecated any time soon.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.