views:

52

answers:

4

The width attribute for <pre>, which defines maximum character length per line, was deprecated in HTML 4.01, and I no longer see it in current draft of HTML5. I couldn't find the reason behind it in the mailing lists of W3C's WG for HTML (maybe I searched wrong), although the specs for 4.01 said it was not supported in all clients.

  1. One possible answer: it makes no sense to wrap preformatted texts. Is this true?
  2. In case I still want it to wrap after for example 30 characters. Besides scripting, how do I achieve this?
+1  A: 

HTML is for defining the structure of a document, not for styling of it. And there is a similar CSS property called width.

floatless
No, CSS property `width` is a different thing. It defines the width for its box model. The `width` attribute for `<pre>` is for either font-scaling, or characters per line, according to the specs (doesn't make sense to me either).
syockit
+2  A: 

Presentational defining attributes were deprecated in favor of CSS. You should not rely on size, width, height attributes but instead focus on semantics when doing the markup. ( Though one exception is probably the img element for preload rendering purposes ).

meder
`<img>` has width and height because it is semantically meaningful for an image to have those properties.
You
A: 

Not a conclusive answer, but it looks like it was deprecated because it was never properly supported (and because it's a presentational concern, and therefore not really something HTML should contain)....

Take a look at it's mention in the HTML 4.01 spec, it mentions it's not widely supported and that it's used to "select an appropriate font size or indent appropriately"--which sounds pretty far off from "defines the number of characters per row".

The normal reason for these old HTML elements/attributes to go away is that they're better aligned with CSS than HTML--HTML is supposed to be just content, not presentation.

STW
It did also say "The desired width is expressed in number of characters" after that. I wonder what it meant by _selecting an appropriate font size_, does it shrink/enlarge accordingly? The meaning/effect of the two sentences do not mix well.
syockit
@syockit since relatively few fonts are fixed-width it could be to hint that character-width does not dictate a strict-width and requires calculation--or perhaps it was considered for alternative uses like `width="200px"`...
STW
A: 

Well, for one, you'd want to separate content from presentation , and in the case of <pre>, the width is purely presentational. Furthermore, it makes little sense to wrap preformatted text, as you point out. You can do that in CSS if you really want to:

pre {
    width: 30em;
    white-space: pre-wrap;
}
You
`30em` = 30 times height of character. Monospaced characters aren't squares, so this doesn't work. `30ex` doesn't work either, as it refers to height of small letter _x_.
syockit
It's as close as it gets. Most monospace fonts are roughly either `1em` or `1ex` wide. The one SO uses, for example, looks like it's pretty close to `1ex`. You could multiply by some factor as well, in case your font doesn't conform to this. The important thing is that monospace fonts are just that — monospace.
You