HTML <pre> 标籤

Definition and usage

<pre> Tags define preformatted text.

<pre> Text in the element is displayed in a monospaced font, and spaces and line breaks are retained. The text will be displayed exactly as it is written in the HTML source code.

See also:

Tag Description
<code> Define the sample output of a computer program.
<samp> Define keyboard input.
<kbd> Define keyboard input.
<var> Define a variable.

See also:

HTML Tutorial:HTML รูปแบบข้อความ

HTML DOM Reference Manual:Pre object

Instance

Example 1

Preformatted text:

<pre>
text within the pre element
Display in a monospaced font,
At the same time, keep
ช่องว่าง          และ
ชาติตัวเลข
</pre>

ทดลองเอง

ตัวอย่าง 2

วิธีที่จะสร้าง text ที่มีความกว้างเรียบร้อยโดยใช้ CSS:

<div style="width:200px;overflow:auto">
<pre>นี่เป็น pre ที่มีความกว้างเรียบร้อย</pre>
</div>

ทดลองเอง

ความเป็นส่วนตัวโลก

<pre> ตามตารางนี้ ความเป็นส่วนตัวโลกใน HTML

ความเป็นส่วนตัวของเหตุการณ์

<pre> ตามตารางนี้ ความเป็นส่วนตัวของเหตุการณ์ใน HTML

การตั้งค่า CSS โดยมาก

โดยมากที่สุด การแสดงผลที่ใช้ค่าเริ่มต้นตามตารางนี้ <pre> องค์ประกอบ:

pre {
  display: block;
  font-family: monospace;
  white-space: pre;
  margin: 1em 0;
}

ทดลองเอง

การสนับสนุนเบราเซอร์

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
การสนับสนุน การสนับสนุน การสนับสนุน การสนับสนุน การสนับสนุน