[whatwg] Pre, code and semantics in HTML5: Wishful thinking?

Geoffrey Sneddon foolistbar at googlemail.com
Thu Jul 24 06:04:46 PDT 2008


On 22 Jun 2008, at 21:22, Edward Z. Yang wrote:

>> To represent a block of computer code, the pre element can be used
>> with a code element; to represent a block of computer output the pre
>> element can be used with a samp element. Similarly, the kbd element
>> can be used within a pre element to indicate text that the user is to
>> enter.
>
> The implication is that document authors are recommended to use
> <pre><code> to wrap all of their programming code instead of a lone
> <pre>, if they wish to be fully semantic. This feels needlessly  
> verbose
> and abusive of <code>, which traditionally has been used to mark
> single-liners.

Well, that tradition is wrong under HTML 4.01 (pre "tells visual user  
agents that the enclosed text is 'preformatted'", whereas code  
'designates a fragment of computer code').

> It also makes it extremely difficult to style pre as a block for code,
> as the only semantic indication that the contents of the pre block are
> computer code is its child. You'd end up having to say <pre
> class="code"><code> if you wanted to style pre as well.

There are lots of thing that are semantically desirable in HTML that  
can't be fulfilled using pre-existing CSS selectors. Continuing to  
style "pre" is no less ambiguous and risky as it was under what the  
traditional behaviour is.

> At the same time, I still think the semantics of whether or not a  
> <pre>
> tag indicates a plaintext file, or a piece of ASCII art, or computer
> code, is somewhat important. However, I think this information would  
> be
> more appropriately given as an attribute.

Why go against what HTML 4.01 does? It seems needless to change.


--
Geoffrey Sneddon
<http://gsnedders.com/>




More information about the whatwg mailing list