View Full Version : Is an empty <p/> allowed?
brothercake
04-07-2003, 04:40 PM
I've got code like this:
<!-- mori contacts info -->
<div class="columnBoxAddress">
<p />
<address>
<small>
MORI House<br />
79-81 Borough Road<br />
London<br />
SE1 1FY<br />
</small>
</address>
<p />
</div>
<!-- / mori contacts info -->
The extra <p/> is there so that the whole block is preceded/ended by a paragraph line-break. In an XHTML 1.0 Transitional page it validates fine, but even told, I'm not 100% convinced this is okay?
liorean
04-07-2003, 04:47 PM
It's valid, all right, but only Mozilla that I know of actually interprets it right. Most browsers doesn't support making normally non-empty tags empty in tagsoup rendering mode (html/sgml engine). In xml mode, they should be able to understand it.
Generally, don't do that unless you are writing xml with a namespace that doesn't have any default rendering.
brothercake
04-07-2003, 05:21 PM
It seems to be okay in Opera 7 as well; but not IE ...
ah well; thanks for the input :)
liorean
04-07-2003, 05:26 PM
Ah, I don't think Opera 7 was out yet when I did my testing - or it might be because of the fact I used <script src="" type="" /> for it...
brothercake
04-07-2003, 05:32 PM
Oh right yeah - I've been inclined to use <script /> before, but I remember it not working in something ...
I can't remember whether Opera 7 will deal with XHTML as XML ... I'll try that when I get home.
Catman
04-07-2003, 05:55 PM
From the XHTML 1.0 Specs (Strict) (http://www.w3.org/TR/xhtml1/):
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 />).
This suggests that while it may be okay from XHTML Transitional, it's not okay for XHTML Strict. That being the case, I'd avoid using <p />.
liorean
04-07-2003, 06:20 PM
Heh - you are reading it all the wrong way. The HTML Compatibility guidelines are there to advice you on what XML features you shouldn't use because an HTML tagsoup engine wouldn't support it as much as for making the HTML something that an XML engine would support. This is an XML feature that HTML engines wouldn't recognise, because it didn't exist in HTML. So, in other words, it's perfectly valid in any XML language, including XHTML Strict, Transitional or any other version.
The problem really lies in that HTML tagsoup engines parse <p /> as <P>, which has an optional end tag. In other words, what most tagsoup engines would treat Brothercake's example as, is one address tag wrapped in a paragraph, followed by an empty paragraph; instead of an empty paragraph, followed by one address tag followed by an empty paragraph.
So, in other words, it's a perfectly legal feature, but if you want it to render correctly in non-xml engines, you better use it only on elements that were empty in the html specs.
Catman
04-07-2003, 09:13 PM
That's what I get for not reading the headings.
http://www1.iastate.edu/~wsthune/cps/ted/tedbonk.gif
Tails
04-08-2003, 08:13 PM
I don't know why a <P /> shouldn't work. I mean, P tags go unended in HTML all the time. Unless it has attributes or styles, it doesn't seem necessary to end them. But I wonder if it is layering up in the parent-element stuff of javascript. That could be a complication, but I just treat the tag like a double-<br /> tag.
Roy Sinclair
04-08-2003, 08:51 PM
Why do you need empty paragraphs? Shouldn't you be using the <br /> instead?
brothercake
04-08-2003, 09:12 PM
Because I want the <address> block to have paragraph spacing; I try to avoid using <br /> tags as much as possible, but actually I did end up using them anyway ...
liorean
04-08-2003, 09:30 PM
Can't css paddings or margins provide that instead of the paragraph? Don't write in structure what is only related to presentation, you know...
Skyzyx
04-09-2003, 12:44 AM
Actually, <P> tags are not supposed to go unended, but browsers like IE have allowed it for so long, that it's become commonplace.
<p> should have a closing tag.
Even if <p /> is allowed in a browser, it shouldn't be used because it's not in the spec.
brothercake
04-09-2003, 10:10 AM
You're missing the point - an unclosed <p> is not allowed, but <p/> is not unclosed; it is allowed.
Margins ... well yeah ... but without HTML spacing the address blocks run immediately after each other in text and non-CSS browsers; that's not a design issue, it's a usability issue, hence my wish for HTML-coded paragraph spacing.
It's also semantic - I don't want "a space of x amount", I want "a paragraph line break".
I really want to do this:
<p><address></address></p>
And it strikes me as illogical that <address> is a block level element at all - particularly when it can also be used for contact names, numbers etc (things which are often inline) and not just postal addresses (which typically are blocks or discreet lines). If it were inline I would have never have had this problem.
liorean
04-09-2003, 10:13 AM
Skyzyx - No, you're wrong at that. In the initial HTML version, a paragraph wasn't a wrapping element at all, it was an empty one. It didn't represent the paragraph itself, it represented a paragraph break. HTML 4 (or maybe 3.2, I haven't read that spec lately) changed it to be wrapping a paragraph.
If you look at the specs, you find some things are incompatible between HTML4 and XHTML1: HTML4 doesn't allow / ending empty elements, XHTML1 requires it.
XHTML1 allows any element not having content to be specified as empty. HTML4 doesn't distinguish empty elements, and thus all tags with required end tags have to be closed with the end tag.
HTML4 allows optional closing for some elements. XHTML1 requires closing, whether by specifying them empty or ending them.
HTML4 allows some of the more obscure SGML syntaxes, even if most browsers doesn't support them. XHTML1 only supports XML syntax.
HTML4 allows silent tags and abbreviated attributes. XHTML1 doesn't.
and there's more...
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.