HTML <pre> tagS2C Home   « HTML <pre> tag

Definition

The <pre> tag is used to define preformatted text.

Example


The following text has whitespace and carriage returns that you can't see and just displays normally unless you use the <pre> tag to respect these characters.

<pre>This text will be be displayed in a fixed width font and preserves whitespace and carriage returns.</pre>



This text will be be displayed
  in a fixed        width font and preserves            whitespace
  and carriage    returns.

Attributes

The following attributes can be used with the <pre> tag.


<pre> Specific Attributes
Attribute Value Description Example
There are no required or optional attributes specific to the <pre> tag.
<pre> Global Attributes
Attribute Description Example
Common
classSpecifies a classname for the element allowing you to apply the style of the predefined class to the content.

<pre class="name">Preformatted Text</pre>
idSpecifies a unique id for the element allowing you to apply the style of the predefined id to the content.

<pre id="name">Preformatted Text</pre>
styleSpecifies an inline style for the element allowing you to apply the style to the contentt.

<pre style="color:red;">Preformatted Text</pre>
titleSpecifies an inline style for the element allowing you to apply the style to the content.

<pre title="Content info">Preformatted Text</pre>
Keyboard
accesskeySpecifies a keyboard shortcut to associate with the element.

<pre accesskey="a">Preformatted Text</pre>
tabindexSpecifies a tab order for the element.

<pre tabindex="1">Preformatted Text</pre>
Language
dirSpecifies the directional flow of the content.

<!-- The text will flow from left to right -->
<pre dir="ltr">Preformatted Text</pre>
<!-- The text will flow from right to left -->
<pre dir="rtl">Preformatted Text</pre>
langSpecifies a language code for the content of the element.

<pre lang="en">Preformatted Text</pre>
spellcheckSpecifies an inline style for the element allowing you to apply the style to the contentt.

<!-- Valid values true and false. -->
<!-- Default inherited / browser specific. -->
<pre spellcheck="true">Preformatted Text</pre> 
translateSpecifies an inline style for the element allowing you to apply the style to the content.

<!-- Valid values yes and no. -->
<!-- Default yes. -->
<pre translate="no">Preformatted Text</pre> 
Miscellaneous
contenteditableSpecifies whether the content of the element is editable.

<!-- Valid values true and false. -->
<!-- Default inherited. -->
<pre contenteditable="true">Preformatted Text</pre> 
draggableSpecifies whether the element is draggable.

<!-- Valid values true and false. -->
<!-- Default browser specific. -->
<pre draggable="true">Preformatted Text</pre>
hiddenSpecifies whether the element is not yet, or no longer, relevant.

<!-- Valid values an empty string or hidden -->
<pre hidden>Preformatted Text</pre> 
<pre hidden="hidden">Preformatted Text</pre> 
<pre> Event Attributes
Attribute Description Example
Document Element
oncopyThe script to be run when the user copies the content of an element.

 <!-- Executes go() function -->
<pre oncopy="go()">Preformatted Text</pre> 
oncutThe script to be run when the user cuts the content of an element.

 <!-- Executes go() function -->
<pre oncut="go()">Preformatted Text</pre>
onpasteThe script to be run when the user pastes some content into an element.

 <!-- Executes go() function -->
<pre onpaste="go()">Preformatted Text</pre>
Drag and Drop
ondragThe script to be run when an element is dragged.

 <!-- Executes go() function -->
<pre ondrag="go()">Preformatted Text</pre>
ondragendThe script to be run when an element has stopped being dragged.

 <!-- Executes go() function -->
<pre ondragend="go()">Preformatted Text</pre>
ondragenterThe script to be run when an element has been dragged to a valid drop target.

 <!-- Executes go() function -->
<pre ondragenter="go()">Preformatted Text</pre>
ondragleaveThe script to be run when an element leaves a valid drop target.

 <!-- Executes go() function -->
<pre ondragleave="go()">Preformatted Text</pre>
ondragoverThe script to be run when an element is being dragged over a valid drop target.

 <!-- Executes go() function -->
<pre ondragover="go()">Preformatted Text</pre>
ondragstartThe script to be run at the start of a drag operation.

 <!-- Executes go() function -->
<pre ondragstart="go()">Preformatted Text</pre>
ondropThe script to be run when a dragged element is being dropped.

 <!-- Executes go() function -->
<pre ondrop="go()">Preformatted Text</pre>
Form
onblurThe script to be run when the element loses focus.

 <!-- Executes go() function -->
<pre onblur="go()">Preformatted Text</pre>
onchangeThe script to be run when object changed and attempt to leave field.

 <!-- Executes go() function -->
<pre onchange="go()">Preformatted Text</pre>
oncontextmenuThe script to be run when a context menu is triggered.

 <!-- Executes go() function -->
<pre oncontextmenu="go()">Preformatted Text</pre>
onfocusThe script to be run when the element gets focus.

 <!-- Executes go() function -->
<pre onfocus="go()">Preformatted Text</pre>
oninputThe script to be run when an element gets user input.

 <!-- Executes go() function -->
<pre oninput="go()">Preformatted Text</pre>
oninvalidThe script to be run when an element is invalid.

 <!-- Executes go() function -->
<pre oninvalid="go()">Preformatted Text</pre>
onresetThe script to be run when a dragged element is being dropped.

 <!-- Executes go() function -->
<pre onreset="go()">Preformatted Text</pre>
onselectThe script to be run when some or all of the contents of an object are selected.

 <!-- Executes go() function -->
<pre onselect="go()">Preformatted Text</pre>
onsubmitThe script to be run when a form is submitted.

 <!-- Executes go() function -->
<pre onsubmit="go()">Preformatted Text</pre>
Keyboard
onkeydownThe script to be run when an element is in focus and keyboard key is pressed down.

 <!-- Executes go() function -->
<pre onkeydown="go()">Preformatted Text</pre>
onkeypressThe script to be run when an element is in focus and keyboard key is pressed down and released.

 <!-- Executes go() function -->
<pre onkeypress="go()">Preformatted Text</pre>
onkeyupThe script to be run when an element is in focus and keyboard key is released.

 <!-- Executes go() function -->
<pre onkeyup="go()">Preformatted Text</pre>
Media
onabortThe script code to be run on abort.

 <!-- Executes go() function -->
<pre onabort="go()">Preformatted Text</pre>
oncanplayThe script to be run when a file has buffered enough so it is ready to start playing.

 <!-- Executes go() function -->
<pre oncanplay="go()">Preformatted Text</pre>
oncanplaythroughThe script to be run when a file can be played all the way to the end without further need of buffering.

 <!-- Executes go() function -->
<pre oncanplaythrough="go()">Preformatted Text</pre>
oncuechangeThe script to be run when the cue changes when using the track element.

 <!-- Executes go() function -->
<pre oncuechange="go()">Preformatted Text</pre>
ondurationchangeThe script to be run when the length of the media is changed.

 <!-- Executes go() function -->
<pre ondurationchange="go()">Preformatted Text</pre>
onemptiedThe script to be run when a media resource element suddenly becomes empty, usually due to an error.

 <!-- Executes go() function -->
<pre onemptied="go()">Preformatted Text</pre>
onendedThe script to be run when the media has reach the end.

 <!-- Executes go() function -->
<pre onended="go()">Preformatted Text</pre>
onloadeddataThe script to be run when media data is loaded and playback can start.

 <!-- Executes go() function -->
<pre onloadeddata="go()">Preformatted Text</pre>
onloadedmetadataThe script to be run when metadata has been loaded.

 <!-- Executes go() function -->
<pre onloadedmetadata="go()">Preformatted Text</pre>
onloadstartThe script to be run whenthe media resource has started loading.

 <!-- Executes go() function -->
<pre onloadstart="go()">Preformatted Text</pre>
onpauseThe script to be run when the media resource has been paused.

 <!-- Executes go() function -->
<pre onpause="go()">Preformatted Text</pre>
onplayThe script to be run when the media resource starts playback.

 <!-- Executes go() function -->
<pre onplay="go()">Preformatted Text</pre>
onplayingThe script to be run when when playback has already begun.

 <!-- Executes go() function -->
<pre onplaying="go()">Preformatted Text</pre>
onprogressThe script to be run when the browser is fetching the media data.

 <!-- Executes go() function -->
<pre onprogress="go()">Preformatted Text</pre>
onratechangeThe script to be run when the playback rate changes.

 <!-- Executes go() function -->
<pre onratechange="go()">Preformatted Text</pre>
onseekedThe script to be run when the seeking attribute is set to false indicating that seeking has finished.

 <!-- Executes go() function -->
<pre onseeked="go()">Preformatted Text</pre>
onseekingThe script to be run when the seeking attribute is set to true indicating that seeking is currently active.

 <!-- Executes go() function -->
<pre onseeking="go()">Preformatted Text</pre>
onstalledThe script to be run when the browser is unable to continue fetching media data.

 <!-- Executes go() function -->
<pre onstalled="go()">Preformatted Text</pre>
onsuspendThe script to be run when media data has stopped before being completely loaded.

 <!-- Executes go() function -->
<pre onsuspend="go()">Preformatted Text</pre>
ontimeupdateThe script to be run when the media resources current playback position has changed.

 <!-- Executes go() function -->
<pre ontimeupdate="go()">Preformatted Text</pre>
onvolumechangeThe script to be run when the volume has changed or been muted.

 <!-- Executes go() function -->
<pre onvolumechange="go()">Preformatted Text</pre>
onwaitingThe script to be run when the media resource has paused but is expected to resume.

 <!-- Executes go() function -->
<pre onwaiting="go()">Preformatted Text</pre>
Mouse
onclickThe script to be run when when a mouse is clicked on an element.

 <!-- Executes go() function -->
<pre onclick="go()">Preformatted Text</pre>
ondblclickThe script to be run when a mouse is double clicked on an element.

 <!-- Executes go() function -->
<pre ondblclick="go()">Preformatted Text</pre>
onmousedownThe script to be run when he mouse button is pressed down while the cursor is over an element.

 <!-- Executes go() function -->
<pre onmousedown="go()">Preformatted Text</pre>
onmousemoveThe script to be run when the mouse button is moved.

 <!-- Executes go() function -->
<pre onmousemove="go()">Preformatted Text</pre>
onmouseoutThe script to be run when the mouse cursor moves off an element.

 <!-- Executes go() function -->
<pre onmouseout="go()">Preformatted Text</pre>
onmouseoverThe script to be run when the mouse cursor moves over an element.

 <!-- Executes go() function -->
<pre onmouseover="go()">Preformatted Text</pre>
onmouseupThe script to be run when the mouse button is released while the cursor is over the element.

 <!-- Executes go() function -->
<pre onmouseup="go()">Preformatted Text</pre>
onwheelThe script to be run when the mouse wheel rolls up or down over an element.

 <!-- Executes go() function -->
<pre onwheel="go()">Preformatted Text</pre>
Scroll
onscrollThe script code to be run when the scrollbar of an element is being scrolled.

 <!-- Executes go() function -->
<pre onscroll="go()">Preformatted Text</pre> 
Window - NONE

Relevant HTML Tutorials

HTML Intermediate - More Formatting