Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

html

xhtml

tags

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

like image 920
Joemon Avatar asked Mar 02 '10 05:03

Joemon


People also ask

What is the use of pre tag in HTML?

The <pre> tag defines preformatted text. Text in a <pre> element is displayed in a fixed-width font, and the text preserves both spaces and line breaks. The text will be displayed exactly as written in the HTML source code.

What is the use of pre tag in HTML Class 7?

The <pre> tag in HTML is used to define the block of preformatted text which preserves the text spaces, line breaks, tabs, and other formatting characters which are ignored by web browsers.


2 Answers

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.

like image 24
naivists Avatar answered Oct 05 '22 02:10

naivists


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 | +-----+------------------+--------+------------+

like image 121
JasonWoof Avatar answered Oct 05 '22 02:10

JasonWoof