Html tag: Pre or Code?

Deja tu comentario

Cual es la diferencia entre usar PRE o usar CODE cuando queremos motrar un código en nuestra página?

Es una simple duda...

Partiendo de lo que dice la Wikipedia:
A code snippet. Conventionally rendered in a monospace font: Code snippet.
CODE existed in HTML Internet Draft 1.2, and was standardised in HTML 2.0; still current.
Pre-formatted text. Text within this element is typically displayed in a non-proportional font exactly as it is laid out in the file (see ASCII art). Whereas browsers ignore whitespace for other HTML elements, in pre, whitespace should be rendered as authored. (With the CSS properties: {white-space: pre; font-family: monospace;}, other elements can be presented in the same way.) This element can contain any inline element except: image (img), object (object), big font size (big), small font size (small), superscript (sup), and subscript (sub).
PRE existed in HTML Internet Draft 1.2, and was standardised in HTML 2.0; still current.

Personalmente, me gusto esta opinion tomada de la red (@jlhaslip):
Semantically, the pre tag is for "pre-formatted" text, not neccesarly (sp?) code only.
The "code" tag is semantically designated to apply to 'code'.
There may be a difference in the selection of styling which the author may wish to apply for preformatted and code sections of the document, so there are two tags.
Think of them as "classes", sort of.

Looking back at the original WWW, the Internet was very different then. There were mostly text documents from Academics being passed around on the Web, and these were very distinctly identifiable requirements. The 'code' sections were typically displayed using a teletype style of character because the most common input device used then for remote access were modified teletype machines and their print type was very different from the print on typewriters, for example, so when the WWW came along, using the teletype font was used to indicate that code was being presented.

Preformatted text could be displayed in any chosen type, not neccesarly the same font as code. Today, though, the code tag is a bit of an anachronism, I agree. You almost need to be my age to remember those times.

I hope this clarifies why these two tags are used in HTML


Publicar un comentario

Nota importante: aquellos comentarios que tengan spam (o contenido ofensivo) serán ELIMINADOS; no editados... sino que directamente se los elimina.