You are here: Home / Dog Blog / Archives

<pre> Is Not Presentational!

Saturday 27 November, 2004 ( 4:41PM GMT)

"You shouldn't really use the pre tag because it's presentational. You should use the CSS statement white-space: pre instead."

NO!

You use pre when the spacing in between characters is just as important and meaningful as the characters themselves.

I just needed to get that out of my system...

Comments

Comment 1

And what's the source of the quote?

"Preformatted" -- sound like formatting to me! But is formatting part of the content or the presentation? Depends on the content, I guess.

So said Gabriel Mihalache on Saturday 27 November, 2004 at 5:19PM GMT.

Comment 2

<pre> is neighbours with <blockquote>, and cousins to <strong> and <em>. I mean, under the argument for not using <pre>, you shouldn't use <strong> or <em>, but instead put a <span> on the text with the bold css'd.

So said Gabriel Koen on Saturday 27 November, 2004 at 6:39PM GMT.

Comment 3

I dislike the pre tag intensely. That's not to say it's wrong. I just don't like it.

I just needed to get that off my chest! :-)

So said John Oxton on Saturday 27 November, 2004 at 9:06PM GMT.

Comment 4

I prefer to use css to style the code tags as preformatted. I also agree with Gabriel K though, kinda (if I know what he means). You definately shouldn't be using spans in the place of em and strong, because both of those hold true semantic value, whereas a span holds none when used without styles and the such.

I would not use the pre tag, except for ie having appearent problems with white-space: pre;, or does it work? I tried a while back on a complex page, but I might try again sometime.

So said Jeff on Sunday 28 November, 2004 at 12:54AM GMT.

Comment 5

The dog has it right. PRE is not presentational when the whitespace in the text is ingrained in the content. It's the same logic as not using CSS image replacement for an image that's, say, part of an article.

Think about it this way: Markup should correctly display the content even when the CSS is stripped away. If you use <span style="white-space: pre;">, that won't translate into browsers which don't support CSS (or users who turn stylesheets off). If the spacing is critical to the content, such users won't be able to read it.

So said Chris Vincent on Sunday 28 November, 2004 at 4:11AM GMT.

Comment 6

You really mean "pre element" I guess. I'm with you on this though, it's just that we don't have better elements.

So said Anne on Sunday 28 November, 2004 at 11:25AM GMT.

Comment 7

When exactly would the white space be as important?

Because with code you should use the code tags, and anything else is just applying its style to the content.

An example would help your case, and in fact the very definition of the tags would suggest that it is for formatting, not meaning. I can't actually think of a use of it that isn't presentational.

So said DarkCryst on Monday 29 November, 2004 at 4:34PM GMT.

Comment 8

Poems? I think you can't use the inline element CODE when you want to display a large chunk of it, by the way. (This is, in case it isn't obvious, in reply to comment 7.)

So said Anne on Monday 29 November, 2004 at 6:26PM GMT.

Comment 9

this tag seems to be very helpful when need is of presenting simple tables in web pages
i mean one can really try to do it using css but i don't see a decent way to do it simply yet
otherwise d'accord :)

So said jordan on Tuesday 30 November, 2004 at 1:31PM GMT.

Comment 10

Oh, this is sticky. And I wouldn't be surprised to be named the source of the quote.

<pre> presupposes that the whitespace is vital to the content. Major point.

Generally, HTML Dog promotes a separation between presentation and content. That is, if it's red text, that's decoration, not content. So red color is to be suggested in the CSS.

Now, what about italics? Italics could be noting emphasis (<em>), or it could represent a variable (<var>). Or it could be just decorative.

But what if, in the standard style for the language in question, italics have MEANING? For example, the "Dies Irae" from Faure's <i>Requiem</i>, or an attack on the <i>USS Cole</i>? If we use CSS for these instances of italics, we make the no-CSS (and totally legitimate) rendering of the HTML lose the semantics the italics represent. By using the <i> element, we are imposing presentation within the content.

Sometimes, presentational traits are intrinsic to the content.

Back to <pre>. This element preserves whitespace. But isn't whitespace, by definition, presentational? Of course! So if you champion separation of presentation and content, you cannot approve of <pre>. You'd be OKing the inclusion of presentational information within the HTML.

Guess what? The division of presentation vs content is a lie.

The trick is to be able to discern between decorative space and integral space. If the content demands a specific spacing (a snippet of code as indented by the author, a poem formatted for artistic visual effect, etc.) then the content demands a particular presentation.

Basically, this means that so long as we can semantically back up the HTML we use, it doesn't matter whether we use markup which includes specific presentational aspects. So long as we understand that some presentation is decorative, and some is connected to meaning, the way we treat such presentation must vary.

The real divide is not between presentation and content; it is squarely between decoration and meaning, and it's as simple as that.

So said Neal on Wednesday 1 December, 2004 at 8:44AM GMT.

Comment 11

Absolutely. A key question for me is always "does this page 'work' without the CSS"? Does the content make sense viewed in a non-styled enviroment? Far too many people forget this very important factor. The world is not just a CSS compliant browser like Mozilla. it's beyond that.

So said Andrew on Wednesday 1 December, 2004 at 4:51PM GMT.

Comment 12

I agree with Neal (comment 10)

"The real divide is not between presentation and content; it is squarely between decoration and meaning, and it's as simple as that."

We design page tally with our purpose in despite of quomodo. The real divide is for web maintenance.

YBB from China

So said YBB on Tuesday 7 December, 2004 at 1:47PM GMT.

Comment 13

For example, the "Dies Irae" from Faure's Requiem, or an attack on the USS Cole?
For example, the "Dies Irae" from Faure's Requiem, or an attack on the USS Cole?

I really wish the <code> element had the same default properties as the <pre> element.

So said hemebond on Wednesday 15 December, 2004 at 12:54AM GMT.

Comment 14

FFS

For example, the "Dies Irae" from Faure's <i>Requiem</i>, or an attack on the <i>USS Cole</i>?

So said hemebond on Wednesday 15 December, 2004 at 12:56AM GMT.

Comment 15

FFS

For example, the "Dies Irae" from Faure's <cite>Requiem</i>, or an attack on the <cite>USS Cole</i>?

So said hemebond on Wednesday 15 December, 2004 at 12:56AM GMT.

Comment 16

FFS

For example, the "Dies Irae" from Faure's <cite>Requiem</cite>, or an attack on the <cite>USS Cole</cite>?

So said hemebond on Wednesday 15 December, 2004 at 12:56AM GMT.

Comment 17

Keep em coming hemebond.

So said mark on Thursday 16 December, 2004 at 9:17PM GMT.

Comment 18

I likes me some <pre> tag.
why? ASCII art.

So said Glenn on Saturday 18 December, 2004 at 10:06AM GMT.

Comment 19

My general feeling is that &ltpre> and its cousins &ltstrong> and &ltem> are not presentational because they simply indicate distinction from surrounding content - albeit with default presentation (whitespace, italics, etc.). Default presentation imposed by a browser should not make an element presentational by definition. Browsers impose default attributes on &ltp> elements, for example (top/bottom margins), yet we would not claim that they are presentational in nature.
The &ltpre> element, then, is not presentational. Instead it indicates that the presention should be distinct from surrounding content and browsers have default ways of presenting that distinction. CSS is used to modify the default presentation.

So said Cailean on Wednesday 9 March, 2005 at 12:34AM GMT.

Comment 20

You really mean "pre element" I guess. I'm with you on this though, it's just that we don't have better elements.

So said Alex on Tuesday 5 July, 2005 at 12:39PM GMT.

See Also

^ Top

SiteGround: Fast, reliable, recommended hosting.