The following code segment for an FAQ, which uses XHTML 1.0, will not validate successfully in the W3C validator.
I’m inserting the Q&A into a definition list in order to maintain the question & answer relationship semantically. The problem is, the questions can be multiple paragraphs. And the <dt>
tag, at least in XHTML 1.0, only allows for inline elements. So I can’t put a <p>
tag in there without throwing an error in the W3C validator.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<dl>
<dt>
<p>This is a very long question.</p>
<p>It has multiple paragraphs.</p>
</dt>
<dd>
<p>This is the answer</p>
</dd>
</dl>
</body>
</html>
Is there a semantically better way of coding this using XHMTL 1.0 Transitional?
For reference, the latest similar thread I can find on the topic is this is What is the best way to semanticly structure a FAQ?. The thread was useful, however it does not cover multiple paragraphs in the question.
Using the
dl
element doesn’t seem to be appropriate.XHTML 1.0 uses the element definitions from HTML 4.01, where the
dl
element is defined to be a "definition list". A list of Q&As is probably not a definition list (unless, maybe, the term to be defined is just phrased as question, e.g., "What is the definition of foo?").HTML5 re-defines the
dl
element: it’s no longer a definition list, but an "association list", or "description list". It might be appropriate to use it for Q&As, and thedt
element can now also contain most of the flow content elements (which includesp
). So this might be suitable if you want to use (X)HTML5. (The example fordt
even shows a FAQ.)Possible alternatives, depending on the actual content and context:
p
and rely on textual semantics, i.e., the "?" makes clear that it’s a question. You could also prefix them with "Question:" and "Answer:" (e.g., inb
).h1
-h6
) for each Q&A. As they neither may containp
elements, you might have to use something like "Question 1" as heading content, and rely on the text again.