views:

199

answers:

6

For example:

This is ok

<div>
<p>some <strong>long</strong> text</p>
<strong>- end -</strong>
<p>some long text</p>
</div>

Or this is more semantically correct?

<div>
<p>some <strong>long</strong> text</p>
<p><strong>- end -</strong></p>
<p>some long text</p>
</div>
+3  A: 

If it isn't a paragraph, then it shouldn't be marked up as a paragraph. (The HTML specification explains how to read the DTD to determine what elements are allowed at a given point in a document.)

<p><strong>- end -</strong></p>

… however, I don't know what this is. You should follow the normal rules for grammar.

David Dorward
<strong>- end -</strong> this is a indication of end of paragraph after each paragraph in MS word file which i got from client
metal-gear-solid
Then the semantic solution is: `</p>`
David Dorward
There's a `<strong> - end - </strong>` at the end of *every paragraph*? That's...interesting. If they're using it like that *and* they want to keep the content, then `<br/><strong> - end - </strong></p>` is the answer. But I prefer David's -- just `</p>` and drop the thing, if they'll let you.
T.J. Crowder
you mean even <strong> is valid but we should wrap in <p>.
metal-gear-solid
+1  A: 

If the content is not a paragraph, then it is not semantic to mark it as such.

If your end marker is designed to be read, then it is debatable whether or not it is actually a paragraph or not. If it's not designed to be read, then it shouldn't be marked up with reading-oriented tags like <strong>, but instead should be in a span or div with a stylesheet applied to make the font weight bold.

Amber
+2  A: 

Academic answer: both are XHTML-compatible. Practical answer: browsers won't give a sh@t about it

Dercsár
A: 

As you mentioned the lower is more semantically correct as the <strong> tag is not a block level element which means you need to wrap it in the <p>. Otherwise I'm sure you will come across issues when you try and validate your HTML.

Rob Such
There are plenty of elements other than `p` that a `strong` element may be a child of. Also, "Validity" and "Semantics" are very different things.
David Dorward
Agreed. But as far as using just <strong>This is Bold</strong> you will come into issues with validating your HTML.
Rob Such
In the example given in the question, the `strong` element is a child of `div` element … which is valid.
David Dorward
A: 

The spec doesn't say you have to. The validator is happy for you to have it in some other block-level container.

T.J. Crowder
A: 

Seems to me that "- end -" is a case for an <hr/> or a p:after{content:"-end-"}

graphicdivine
p:after{content:"-end-"} is supported in all browsers?
metal-gear-solid
No, it isn't, but if it is purely presentational this may not be critical.
graphicdivine