tags:

views:

123

answers:

4

what is the use of a "PRE" tag in (X)HTML

+1  A: 

It is used to demonstrate pre-formatted text, where new-line breaks are relevant. For instance, ascii art ;-) or program code. Well, for program code the CODE element is better.

naivists
In that case, it's common to use both: `<pre><code> helloWorld() </code></pre>`
nickf
In fact, that's exactly what Stack Overflow does. `inline ones like this` are `<code>` and the blocks are `<pre><code>`.
nickf
+1  A: 

The PRE element represents a character cell block of text and is suitable for text that has been formatted for a monospaced font.

The PRE tag may be used with the optional WIDTH attribute. The WIDTH attribute specifies the maximum number of characters for a line and allows the HTML user agent to select a suitable font and indentation.

Hypertext Markup Language - 2.0 specs from W3C

codaddict
+4  A: 

It's for displaying data/code/art where you want all your spaces and newlines to be displayed as is, and want your columns to line up. So you can do stuff like this:

+-----+------------------+--------+------------+
| id  | session_key      | length | expires    |
+-----+------------------+--------+------------+
| 263 | SNoCeBJsZkUegA7F |  86400 | 1257401198 |
| 264 | UoVm3SZRmPHnac4V |  86400 | 1257405561 |
| 262 | bjkIOWBhI1qxcrWr |  86400 | 1257401189 |
+-----+------------------+--------+------------+

without "pre" or "code" or some such, this looks like this:

+-----+------------------+--------+------------+ | id | session_key | length | expires | +-----+------------------+--------+------------+ | 263 | SNoCeBJsZkUegA7F | 86400 | 1257401198 | | 264 | UoVm3SZRmPHnac4V | 86400 | 1257405561 | | 262 | bjkIOWBhI1qxcrWr | 86400 | 1257401189 | +-----+------------------+--------+------------+

JasonWoof
+1. Excellent visualization.
D_N
+1  A: 

Have you ever looked an article posted in code project site ? If you didn't take a look at it this http://www.codeproject.com/KB/game/Hangman_game.aspx. From the article the yellow section or the one with collapse and expand code snippet are pre taged. It helps to preserve the data the way it is written or presented as it is without distorted.

Wonde