HTML5 Reference

HTML <pre> tag

Definition

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

Example


The following text has whitespace and carriage returns tht you can't see and just displays normally unless you use the <pre> 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 Lessons - Formatting