Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Are there any non-semantic (i.e. actual) differences between the <p>
tag and the <div> tag?



bgold12 wrote:
Quoted text here. Click to load it

Among other things ...

You cannot nest a DIV (or any other block) within a P, but you can nest
a P (or another block) within a DIV.

Ps and DIVs likely have different default margins and padding.

Speech-based browsers, e.g. for the blind, should treat them differently.



In article

Quoted text here. Click to load it

There are the ways they are regarded by browsers partly because of their
meaning or lack of. In English at least, paragraphs, which are sets of
sentences that have some common thought are traditionally typeset with
some margin at top and bottom. These styles are defaulted to, not always
exactly the same for each browser but they all try to capture the

In other words, there are non semantic things about them that
distinguish them. These arise because of the semantic intentions (which
is nothing in the case of the div). Browsers set these defaults so that
readers can see they are paragraphs...

You can, course, override the style defaults.

And there are other differences too in what you can and cannot have as
their children.  And these flow from meaning in most cases. Let's stay
with 4.01 Strict.

You can have




but not




You can't have the last because it has no meaning. A paragraph within a
paragraph? Well, maybe there could be some sense in it but it is a bit
of a stretch.

Why you can't have the one before that is complicated, the p
element/4.01 HTML makers were perhaps a little over-religious about

"The P element represents a paragraph. It cannot contain block-level
elements (including P itself)."

It is reasonable to ask quite why.

You can have:

<img style="display: block;" src="pics/crimson.png" alt="">

But that is because the normally inline image crept into the p element
and then sneakily changed to being a block box before it could be kicked
right out of there. <g>

You can't (in a special sense of can't) have the eminently reasonable


Absurd of course, but that is how it is. Perhaps you can just be
reasonable and let validators scream?

I better stop. People love talking about these things and you will get
more for sure.


Site Timeline